Back to troubleshooting
troubleshooting#nginx#debugging#networking

Nginx 502 Bad Gateway after Deploy

Nine times out of ten it's one of these five issues — here's how to isolate them.

Jane Contributor August 2, 2026 3 views

Problem

After a routine deploy, Nginx returns 502 Bad Gateway. The upstream app appears to be running.

Step-by-step Solution

  1. 1`curl -v http://localhost:<app-port>` on the box — confirm the app actually answers.
  2. 2Check `/var/log/nginx/error.log` — look for `connect() failed`, `upstream timed out`, or `no live upstreams`.
  3. 3Verify `upstream` block ports match the app's listening port (`ss -tlnp`).
  4. 4If Docker: is the app bound to `0.0.0.0` and not `127.0.0.1`? Container `localhost` != host.
  5. 5Increase `proxy_read_timeout` and `proxy_connect_timeout` for slow-starting apps.
  6. 6Reload cleanly: `nginx -t && nginx -s reload`.
  7. 7Add a `/healthz` endpoint and use `proxy_next_upstream` to fail over on transient errors.

See problem and step-by-step solution above.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.