Menu

How to Fix a 502 Bad Gateway in Nginx (Without Guessing)
📰

How to Fix a 502 Bad Gateway in Nginx (Without Guessing)

DEV Community: docker·The Practical Stack·about 7 hours ago
#9Q8oMb1v
#devtodocker#devto#dev#nginx#container
Long article (448 words) — no AI summary yet.
Reading 0:00
15s threshold

A 502 means your reverse proxy got the request fine — but the app behind it didn't answer properly. Before touching any config, find out which layer is actually failing. That one habit fixes most 502s in minutes.

The 4 causes that cover almost every 502

What the log says What it usually means

connect() failed (111: Connection refused) The app crashed, is bound to the wrong address, or the port is wrong

upstream prematurely closed connection A worker timed out, or the container was killed for running out of memory

upstream sent too big header Large cookies / auth headers overflow Nginx's default proxy buffers

connect() to unix:/run/php/php8.3-fpm.sock failed (13: Permission denied) The socket file is owned by a different user than Nginx runs as

Step 1 — Read the error log first

sudo tail -n 5 /var/log/nginx/error.log sudo docker ps -a --format "table {{.Names}} {{.Status}} {{.Ports}}"

Enter fullscreen mode

Exit fullscreen mode

The log line tells you the exact failure.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.