Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

We have configured Nginx as a reverse proxy to an Apache server farm, but I'm running into trouble with the gateway timeouts.

Our Goal in human readable form is: "Deliver a request within one second, but if it really takes longer, deliver anyway", which for me translates into "Try the first Apache server in upstream for max 500ms. If we get a timeout / an error, try the next one and so on until we finally succeed."

Now our relevant configuration is this:

location @proxy {
    proxy_pass         http://apache$request_uri;

    proxy_connect_timeout 1s;
    proxy_read_timeout 2s;



upstream apache {
 server          max_fails=1 fail_timeout=10s;
 server 10.1.x.x:8001           max_fails=1 fail_timeout=10s backup;
 server 10.1.x.x:8001           max_fails=1 fail_timeout=10s backup;
 server 10.1.x.x:8001           max_fails=1 fail_timeout=10s backup;

The problem here is that nginx seems to misunderstand this as "Try to get a response from the whole upstream cluster within one second and deliver a 50X error if we don't - without any limit on how long to try any upstream server", which is obviously not what we had in mind.

Is there any way to get nginx to do what we want?

share|improve this question

migrated from stackoverflow.com Aug 26 '12 at 14:02

This question came from our site for professional and enthusiast programmers.

Nginx isn't "misunderstanding", proxy_connect_timeout applies to the entire upstream, so you are explicitly telling Nginx to only try for 1s before failing. Also, your "human readable" goal doesn't say much except "take as long as you like". –  cliff.wells Jul 11 '12 at 18:35
proxy_read_timeout 500ms and max_fails=0 should work better. –  sendmoreinfo Sep 14 '12 at 4:42

1 Answer 1

This directive is missing under example location:

proxy_next_upstream     error timeout;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.