nginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.
IntermediateTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → Every server in the upstream block is marked failed by passive health checking (max_fails within fail_timeout). One short outage or a burst of errors can mark all of them down at once, and nginx then refuses to try any until fail_timeout expires.
Diagnose →
grep -B3 'no live upstreams' /var/log/nginx/error.log | head -20 # what failed first?
nginx -T | grep -A10 'upstream app'
Fix → Fix the underlying failure first. Then tune: server 10.0.1.10:8080 max_fails=3 fail_timeout=10s;, and avoid tiny upstream pools. Note that proxy_next_upstream codes such as http_500 also count as failures.
Prevent → Use active health checks (NGINX Plus, HAProxy, Envoy, or an LB) and alert when more than half the pool is down.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.IntermediateAn NLB shows all targets healthy, but clients from the internet time out connecting through it.Intermediate