Back to blog
Linux & Servers Published November 23, 2026

Fix: nginx no live upstreams while connecting to upstream (502 Bad Gateway)

Automate WhatsApp Alerts
Start Free ➔
2026/11/23 09:41:07 [error] 1234#1234: *412 no live upstreams while connecting to upstream, client: 203.0.113.7, server: example.com, request: "GET /api/orders HTTP/1.1", upstream: "http://backend/api/orders", host: "example.com"

Visitors see 502 Bad Gateway. The log line says Nginx didn't even try to connect: it had already decided that every server in the upstream block was unavailable.

Quick fix: find out why the backends were marked as failed (they were down, slow, or returning errors that Nginx counts as failures), fix that, then make the failure rules less trigger-happy:

upstream backend {
    server 10.0.0.11:3000 max_fails=3 fail_timeout=30s;
    server 10.0.0.12:3000 max_fails=3 fail_timeout=30s;
}
sudo nginx -t && sudo systemctl reload nginx

A reload also clears the failed marks straight away, so it brings traffic back if the backends are healthy again. It won't stop the problem from returning.


1. How Nginx decides an upstream is "dead"

Nginx watches each server in an upstream block. When a request to a server fails (connection refused, timeout, or any response type you listed in proxy_next_upstream), it counts one failure. After max_fails failures within fail_timeout (defaults: 1 failure, 10 seconds), Nginx treats that server as unavailable for the next fail_timeout seconds and sends traffic elsewhere.

When all servers are marked unavailable at once, there is nowhere left to send the request. Nginx logs no live upstreams and returns 502 immediately, even if the backends have already recovered. That is why the error often lasts for about 10 seconds after a short backend hiccup.


2. Check what the backends were doing

Look in the log just before the first no live upstreams line. The real cause is usually right above it:

sudo grep -B 5 "no live upstreams" /var/log/nginx/error.log | head -40

Typical neighbours:

Line just beforeWhat it meansGuide
connect() failed (111: Connection refused)App crashed, restarting or on the wrong port111 guide
upstream timed out (110: Connection timed out)App too slow or overloaded110 guide
upstream prematurely closed connectionApp dropped the connection mid-responsePrematurely closed guide
host not found in upstreamDNS name can't be resolvedDocker DNS guide

Then test each backend directly from the Nginx machine:

curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" http://10.0.0.11:3000/health
curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" http://10.0.0.12:3000/health

If both answer quickly, the backends are fine now and the failures were short or were triggered by a setting (section 3).


3. Settings that make Nginx give up too easily

  • Defaults are strict. One failed request marks a server dead for 10 seconds. Two servers failing once each in 10 seconds is enough to take the whole site down. Raise max_fails (3 to 5) and fail_timeout (30s) so a single bad request doesn't remove a server.
  • proxy_next_upstream lists HTTP errors. If you have proxy_next_upstream error timeout http_500 http_502 http_503;, a slow or buggy endpoint that returns 500 counts as a failure for that server, and a few such requests mark healthy servers dead. Keep it to error timeout unless you really want to retry on those statuses, and never retry non-idempotent requests (POST) blindly.
  • One slow endpoint poisons the group. A single heavy URL that times out can mark the servers failed for every other URL too. Give that route its own upstream or a longer proxy_read_timeout in its own location.
  • Servers marked down or a backup that's also down. Check the upstream block for down flags left from maintenance.
location / {
    proxy_pass http://backend;
    proxy_next_upstream error timeout;
    proxy_next_upstream_tries 2;
}

Setting max_fails=0 turns the failure counting off completely: Nginx never marks that server dead. It stops this error, but it also means Nginx keeps sending requests to a backend that is really down, so only do it if something else takes dead servers out of rotation.

A note on a single server: if the upstream block has only one server, Nginx ignores max_fails and fail_timeout and never marks it unavailable. You'll then see connect() failed errors instead. This error needs at least two servers (or a backup).


4. Detecting dead backends properly

Open source Nginx only learns a backend is down when a real visitor's request fails (passive checks). Active health checks, where Nginx probes a /health endpoint, are an Nginx Plus feature. Without Plus, the usual options are:

  • A health check at the load balancer in front (AWS ALB, HAProxy or similar) instead of in Nginx.
  • A process supervisor (systemd, Kubernetes liveness probes) that restarts a stuck app, with enough max_fails leeway to cover a restart.
  • An external monitor that tells you as soon as the site returns 502 (section 6).

5. Errors that look similar

Log messageMeaning
no live upstreams while connecting to upstreamEvery server in the group is currently marked failed (this page)
connect() failed (111: Connection refused)One connection attempt was refused
upstream timed out (110)One attempt was too slow
upstream sent too big headerThe response headers don't fit the buffer: guide

6. Know when it happens

This error comes in short bursts: a backend restart or a slow minute, then it clears. Nobody is watching the log at that moment, but your visitors get 502s.

With Pingzo, an HTTP monitor calls each URL every 1 to 15 minutes depending on your plan. A 502 counts as a failed check, an incident opens when 3 of the last 5 checks fail, and alerts go to WhatsApp, Slack, Telegram, Discord or email. See how to monitor an Nginx web server.


Related guides

Zero-Code Uptime Alerts

Stop Finding Out About Outages from Angry Users

Get instant WhatsApp & Discord alerts the second your API, website, or server goes down. Setup in 30 seconds, with checks as often as every minute.

WhatsApp & Discord 60-Second Checks Free Forever Plan
Try Pingzo Free

Know before your users do

Connect official WhatsApp notification channels, Discord webhooks, Telegram bots, and public status pages. Start in 30 seconds.

Create Free Monitor