DigitalOcean Droplet 502 Bad Gateway (Nginx)
Quick answer
A 502 on a Droplet almost always means Nginx is running but the app behind it (Node, PHP-FPM, Gunicorn) is down, crashed or on a different port or socket. Check the upstream service and Nginx error log.
Most likely fix: Read the Nginx error log
How to fix it
Try these in order — the most common fix is first.
1. Read the Nginx error log
- SSH in and run sudo tail -n 50 /var/log/nginx/error.log
- Look for "connect() failed (111: Connection refused) while connecting to upstream" (app is down) or "No such file or directory" (socket path wrong)
Did this fix it?2. Restart and verify the upstream app
- Check it runs: systemctl status your-app (or php-fpm, gunicorn, pm2 status)
- Confirm the port with sudo ss -plnt and compare with proxy_pass in your Nginx site config
- Restart the app, then sudo nginx -t && sudo systemctl reload nginx
Did this fix it?3. Check memory
- Run free -h and sudo dmesg | grep -i "killed process"
- If the OOM killer ended your app, add swap or resize the Droplet (see the out of memory guide)
Did this fix it?4. If behind a DigitalOcean Load Balancer
- Open Networking > Load Balancers and check the health check path, port and protocol
- Make sure the Droplet firewall allows traffic from the load balancer
Did this fix it?
Symptoms
Browser shows 502 Bad Gateway from nginx while the Droplet itself is up and SSH works.
Why it happens
- App process crashed or was killed because the Droplet ran out of memory
- Nginx proxy_pass points to the wrong port or socket
- PHP-FPM or Gunicorn socket path or permissions changed after an update
- Upstream is overloaded and times out
- Load balancer health checks fail so it has no healthy backend
This guide also covers
- digitalocean 502 bad gateway
- droplet nginx 502 bad gateway
- digitalocean 502 error
- nginx bad gateway digitalocean
Still not working?
If DigitalOcean keeps failing, you're not alone. See every DigitalOcean problem users report or the alternatives people switch to.
Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.
Talk to usOther DigitalOcean errors
- DigitalOcean Droplet SSH Permission Denied (publickey)
- DigitalOcean Droplet SSH Connection Refused or Timed Out
- DigitalOcean Droplet Out of Memory (OOM Killer)
- DigitalOcean App Platform Build Failed
- DigitalOcean App Platform Deploy Failed or 502 After Deploy
- DigitalOcean Account Locked or Verification Required
- DigitalOcean Unexpected Bill: Charged for Deleted or Powered-Off Droplets
- DigitalOcean Droplet Locked Out: Reset Root Password and Recovery Console