Have Nginx hold requests while app is reloading [duplicate]
I have an nginx reverse proxy server set up to forward requests to an app running on port 5000 via proxy_pass http://localhost:5000;
.
This works, however when I restart the app, for about 10 sec any requests immediately return 502 Bad Gateway
, until the app reloads again.
Is there any way to set up Nginx to hold those requests while the app is down, retrying every so often? I've tried
upstream backend {
server localhost:5000 fail_timeout=20s;
server localhost:5000 backup;
}
...
proxy_pass http://backend;
but that doesn't seem to have an effect.
Solution 1:
You have some options :
Search into your upstream doc to find a proper reload signal/api instead of a stop & start sequence.
If your pages can be cached, define a proxy cache and serve stale pages until the app goes up again.
Scale the backend to 2 instances and restart one at a time, then tune
proxy_next_upstream
if necessary.