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.

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

2 Answers 2

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

 
discard

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.