I have many nodejs proxies running behind nginx, it has worked fine for years with 1 annoying exception.
When the nodejs process is restarted, the client receives a 502 error, which is OK, however nginx appears to continue refusing the connection for exactly 30 seconds, and then the connection is restored.
I need to reduce this down to a few seconds, I have seen other posts about increasing timeouts to overcome intermittent gateway errors, however this is different.
I have tried enabling keep-alive with:
proxy_http_version 1.1;
proxy_set_header Connection "";
But that has no effect.
Does anyone know which parameter is controlling this 30 second timeout ?
OK, solved:
proxy_cache_valid 502 5s;
This appears to reduce the time that the server waits after a 502 error before restoring the connection.