Mastering Nginx

(Ron) #1

NGINX as a Reverse Proxy


[ 86 ]

server 127.0.0.1:9002;

}

server {

location / {

error_page 500 502 503 504 = @fallback;

proxy_pass http://app;
}

location @fallback {

proxy_pass http://127.0.0.1:8080;

}
}

The "=" notation shown in the preceding error_page line is used to
indicate that we want to return the status code resulting from the last
parameter; in this case, the @fallback location.

These examples cover cases in which the error code was 500 or greater.


NGINX can also supply an error_page for error codes 400 or greater, when the
proxy_intercept_errors directive is set to on, as in the following example:


server {

proxy_intercept_errors on;

error_page 400 403 404 /40x.html;

location = /40x.html {

root share/examples/nginx/html;

}
}
Free download pdf