Symptom: Users started hitting 504 Gateway Timeout errors intermittently on a production web app fronted by Nginx. No deployments had gone out recently, and the errors weren't consistent — some requests succeeded, others timed out after ~60 seconds.
Root cause: Nginx was acting as a reverse proxy to an upstream application service. The upstream service had entered a degraded state — its worker processes were alive but no longer accepting new connections, likely due to a connection pool exhaustion issue on the app side. Nginx correctly waited for a response, hit its proxy_read_timeout, and returned a 504 to the client.
Fix:
- Confirmed Nginx's error log (
/var/log/nginx/error.log) showed repeatedupstream timed outentries, ruling out Nginx config as the cause. - Checked the upstream service with
systemctl status app-service— process was running but not responding. - Restarted the hung upstream service:
systemctl restart app-service, clearing the stuck connections. - Reloaded Nginx (
systemctl reload nginx) to drop any queued requests pointed at the old worker. - Lowered
proxy_read_timeoutand enabled active health checks on the upstream block.
Result: 504 errors stopped immediately. Added a monitoring alert on upstream response latency to catch this before it reaches users next time.