Skip to content
LinuxNginxTroubleshootingDevOps

Diagnose an Nginx 502 in 10 Minutes: A DevOps Incident

July 10, 2026 · 11 min read

Last verified: 2026-07-17

Frequently Asked Questions

What does a 502 Bad Gateway error mean?

A 502 Bad Gateway means Nginx is up but can't reach the upstream (your app server) behind it. So the problem is usually not in Nginx — it's in the upstream. This mental model dictates the diagnosis order: look at the upstream first.

What is the difference between 502, 503, and 504 errors?

502 means the upstream is unreachable, 504 means the upstream is too slow (timeout), and 503 means the service is temporarily down. The exact code tells you where to look.

How do you diagnose an Nginx 502 error?

In order: read the upstream error in the Nginx log with `journalctl -u nginx`; check whether the upstream port is being listened on with `ss -ltnp`; see if the process is alive or crashed with `systemctl status <app>`; test the upstream directly without Nginx using `curl 127.0.0.1:<port>`; check for resource exhaustion like OOM or a full disk with `free -h`, `df -h`, and `dmesg`; finally check for permission/SELinux issues.

How do you check which process is listening on a port?

Use `sudo ss -ltnp | grep :<port>`. If there is no output, no process is listening on that port, which indicates the upstream app is down. If the output shows a process name and PID (for example nginx or node), the process is up.

Does restarting Nginx fix a 502 error?

No. In a 502 situation Nginx is already healthy; running `nginx -s reload` or `systemctl restart nginx` won't fix it and only delays the symptom. You must fix the upstream first.

Reading isn't enough — do it.

Practice these topics in an interactive terminal in your browser.