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.

  1. Try 127.0.0.1 ... fail!
  2. Try bkupsrv1 ... fail!
  3. Try bkupsrv2 ... fail!
  4. No more servers available. Show bkupsrv2 while ignoring all errors.

Is such a process possible? If not, what alternatives do I have?

link|improve this question
You may have some luck creating a custom error_page 500 @named_location and then in your location @named_location { proxy_pass bkupsrv2:8080; } Add a rewrite to @named_location if you want it to load a path other than the $uri. – cyberx86 Dec 9 '11 at 3:08
@cyberx86 thanks for your suggestion. that is actually the attempt that i will try, except that i'll catch HTTP 502 (bad gateway) instead of HTTP 500. i'll answer my question with the solution as soon as i have tested it (except if someone else answers it before). – Danilo Bargen Dec 12 '11 at 9:01
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.