This question should have been answered a longtime ago, but I can't seem to figure it out despite reading many common answers, can someone please point out why my configuration isn't working?
Goal: when upstream server_api is down (say, its worker processes has crashed), I want nginx to display my custom error page.
My configuration:
location @server {
proxy_pass http://server_api;
proxy_redirect off;
...
proxy_intercept_errors on;
error_page 502 /error-502.html;
}
error_page 502 /error-502.html;
location = /error-502.html {
internal;
root /srv/my-server/html;
}
My steps:
- I have my static error page at
/srv/my-server/html/error-502.html
ready, same permission and owners as other static assets. - I have stopped my upstream service, and see
[error] 2359#0: *25 connect() failed (111: Connection refused) while connecting to upstream
appearing in logs. - Now I try to make my custom error page show up for 502 errors.
- I have tried setting
error_page
at both or eitherserver
orlocation
block. - I have tried
error_page
withproxy_intercept_errors on
in thelocation
orserver
block;
None of them appear to persuade nginx to display my error page. Why not? What have I missed?
server
block.