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.
Problem
After a routine deploy, Nginx returns 502 Bad Gateway. The upstream app appears to be running.
Step-by-step Solution
- 1`curl -v http://localhost:<app-port>` on the box — confirm the app actually answers.
- 2Check `/var/log/nginx/error.log` — look for `connect() failed`, `upstream timed out`, or `no live upstreams`.
- 3Verify `upstream` block ports match the app's listening port (`ss -tlnp`).
- 4If Docker: is the app bound to `0.0.0.0` and not `127.0.0.1`? Container `localhost` != host.
- 5Increase `proxy_read_timeout` and `proxy_connect_timeout` for slow-starting apps.
- 6Reload cleanly: `nginx -t && nginx -s reload`.
- 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
troubleshooting
Kubernetes Pod stuck in CrashLoopBackOff
A methodical checklist to diagnose and fix crash-looping pods in production.
Read
troubleshooting
PostgreSQL: Too Many Connections
The classic Postgres scaling wall — and how PgBouncer solves it.
Read
troubleshooting
K8s Errors Part 3: Cluster / Storage / RBAC / Autoscale
The remaining 20 errors — RBAC, HPA not scaling, PVC pending, ETCD sadness, cert expiry, quotas and more.
Read
Discussion (0)
No comments yet. Be the first to weigh in.