Nginx 502 Bad Gateway Deep Diagnosis Checklist
Nginx 502 Bad Gateway usually means Nginx could not get a valid response from the upstream service. For WordPress, the upstream is often PHP-FPM. For apps, it may be a Docker container, Node.js app or API service.
Core principle
502 is an upstream handoff failure. Nginx is reachable, but the backend is missing, crashed, unreachable or returning invalid data.
Checklist
- Confirm Nginx is responding.
- Identify the upstream for the affected URL.
- Check PHP-FPM or app service status.
- Check socket or TCP upstream target.
- Check whether the upstream is listening.
- Check Nginx error log for connect errors.
- Check backend logs.
- Check resource pressure on the server.
- Restart only the failed backend service if confirmed.
- Verify the URL and monitor logs after recovery.
Reusable lesson
This applies to PHP-FPM, Docker apps, reverse proxies, n8n, APIs, dashboards and custom workers behind Nginx.
When to Use This Checklist
Use this checklist when Nginx returns 502 Bad Gateway for WordPress, PHP apps, Docker apps, APIs or reverse proxy services.
Required Tools
SSH access, Nginx error log, upstream config, PHP-FPM or app service, ss, systemctl, backend logs
Before You Start
Do not blame DNS or SSL first if Nginx is already returning 502. Focus on the upstream handoff.
Structured Checklist Steps
- Confirm Nginx response.
- Identify upstream.
- Check backend service.
- Check socket or TCP target.
- Check listener.
- Read Nginx error log.
- Read backend logs.
- Check resources.
- Restart confirmed failed backend.
- Verify recovery.
Verification Steps
- Upstream target is known.
- Backend service is active.
- Listener exists.
- Nginx error log no longer shows connect failure.
- URL returns expected response.
Rollback Plan
If backend restart does not fix 502, restore recent config changes and test the upstream directly before changing Nginx again.
Common Mistakes
- Restarting Nginx instead of backend.
- Wrong socket path.
- Backend app crashed.
- Docker container not running.
- Ignoring server memory pressure.
Related Commands
curl -I https://example.com
sudo tail -n 100 /var/log/nginx/error.log
sudo systemctl status php8.2-fpm
ls -la /run/php/
sudo ss -tulpn
docker ps
free -h