Fix: Nginx 502 Bad Gateway Error

Nginx returns 502 when it can't get a valid response from the upstream server. The upstream is either not running, on the wrong port, or unreachable on the configured address.

Diagnosis checklist

# 1. Is the upstream service running?
docker ps | grep your-service
systemctl status your-service

# 2. Is it listening on the expected port?
ss -tlnp | grep 3000

# 3. Can Nginx reach it?
curl -sI http://127.0.0.1:3000/

# 4. Check Nginx error log:
tail -50 /var/log/nginx/error.log | grep upstream
Common fix — update proxy_pass port
location / {
    proxy_pass http://127.0.0.1:3000;  # Verify port matches your app
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}
nginx -t && systemctl reload nginx

Paste your nginx.conf to detect dangling routes and wrong upstream ports.

Open Tool →

Related Glossary Terms