← Back to all fixes

Nginx returns 502 Bad Gateway

The Issue

`curl localhost` returns 502 Bad Gateway.

Root Cause

Nginx cannot reach the upstream app. Either the app is down, listening on wrong port, or proxy_pass address is wrong.

How to Fix
  1. Check if your app is running: `systemctl status myapp` or `docker ps`
  2. Verify app is listening: `ss -tlnp | grep 3000`
  3. Test upstream directly: `curl http://localhost:3000`
  4. Read nginx error log: `sudo tail -f /var/log/nginx/error.log`
  5. If using Docker: ensure the app container and nginx can reach each other (same network or use host IP)