Nginx as reverse proxy: how to properly configure gateway timeout?

Posted by user1281376 on Server Fault See other posts from Server Fault or by user1281376
Published on 2012-03-20T16:14:38Z Indexed on 2013/10/22 21:56 UTC
Read the original article Hit count: 138

Filed under:
|
|
|

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 127.0.0.1:8001          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?

© Server Fault or respective owner

Related posts about apache2

Related posts about nginx