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

Nginx returns 502 while the backend is restarting. How can I make nginx proxy retry N times with M seconds delay? Is there a plugin or something else?

share|improve this question

Closest thing I know is this project, but I never used. I know that varnish has backend checking, maybe you want to take a look on it.

share|improve this answer

I found that Nginx took ~2 seconds to exhaust attempts if you specified hundreds of instances of the same backend:

    server  localhost:8080 max_fails=0;
    server  localhost:8080 max_fails=0;
    server  localhost:8080 max_fails=0;
    server  localhost:8080 max_fails=0;

(.... er, repeat as required!)

Yes, a horrendous kludge - but it does add a degree of tenacity...

Even worse than that, you could use:

    server  localhost:8080 max_fails=0;     
    server  localhost:80 backup;        

Assuming Nginx is running on port 80, this would try to continually loop the request around Nginx until localhost:8080 responds. I.e. retry an infinite(?) number of times with zero seconds delay.

I'll get back to my padded cell now....

share|improve this answer
Won't the second approach result in a recursive loop and crash the server? – Seun Osewa Mar 17 '12 at 17:02
@SeunOsewa It does largely depend on how long it takes for the backend to respond but yeah, that's going to overflow at some point. – Oli Dec 18 '12 at 16:33

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.