A 502 Bad Gateway error from Nginx usually means one thing. The web server tried to pass a request upstream and that upstream did not respond in the way Nginx expected. The trick is that several different mistakes can produce that same symptom.

This guide covers common Nginx mistakes that cause 502 errors and how to think through them logically.

Upstream service is down

The obvious explanation is still worth checking first. If PHP-FPM, a Node.js app or another backend is not running, Nginx has nothing useful to talk to.

Wrong socket or port

Nginx may be pointing to a Unix socket or local port that no longer exists, was changed during an update or was typed incorrectly in the config.

Permissions issues

With Unix sockets in particular, the service can be running but still inaccessible if the permissions or ownership are wrong.

Timeouts and slow backends

Some 502 cases are really performance issues. If the upstream is overloaded, hanging or crashing under pressure, Nginx becomes the messenger for a deeper problem.

Final thoughts

When you see a 502, start with the upstream and work outward. Nginx is often reporting the failure, not causing it.

By Tech Tutorial

Hey, I'm Chris! Nerd, Business owner, Serial Procrastinator! Will add more info soon :)