I have a setup with 3 servers. If one of them fails (e.g. with a HTTP500), the others should take over.
Nginx upstream configuration:
upstream appsrv {
server 127.0.0.1:8080 fail_timeout=0;
server bkupsrv1:8080 backup;
server bkupsrv2:8080 backup;
}
...
server {
...
location / {
...
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_pass http://appsrv;
...
}
...
}
The problem is, if all of them fail, the not helpful "bad gateway" error is shown because Nginx does not know which gateway to choose (as all of them fail).
Now what I would prefer is if the HTTP500 error page of the last tried server would be shown.
E.g.
- Try 127.0.0.1 ... fail!
- Try bkupsrv1 ... fail!
- Try bkupsrv2 ... fail!
- No more servers available. Show bkupsrv2 while ignoring all errors.
Is such a process possible? If not, what alternatives do I have?
error_page 500 @named_locationand then in your location@named_location { proxy_pass bkupsrv2:8080; }Add arewriteto@named_locationif you want it to load a path other than the$uri. – cyberx86 Dec 9 '11 at 3:08