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?