Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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
There's no way to tell nginx "deliver in one second, but if it takes longer it's probably okay". Because even in human-readable form this would be "it's okay if the wait will be infinite". So far you failed to define border condition for timeout, and that's why this question has no answer. – drookie Feb 26 at 8:26

Your Answer


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