Fix "502 Bad Gateway" in Nginx & Reverse Proxies
Developer guide and instant terminal command to diagnose and solve this error.
Why Does This Error Happen?
Nginx received an invalid or nonexistent response from the upstream application server (Node.js, Gunicorn, PHP-FPM) because the backend service is stopped or listening on a different port.
Instant Terminal One-Liner Fixes
Comprehensive Step-by-Step Resolution
- 1Verify backend application status: "systemctl status my-app" or "pm2 list".
- 2Check upstream port in /etc/nginx/sites-available/: Ensure proxy_pass matches the active local port (e.g. http://127.0.0.1:3000).
- 3Inspect Nginx error logs: "sudo tail -f /var/log/nginx/error.log".
Troubleshoot using the Nginx Reverse Proxy Config Generator
Use our client-side utility with zero server upload for instant debugging.
Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
Nginx received an invalid or nonexistent response from the upstream application server (Node.js, Gunicorn, PHP-FPM) because the backend service is stopped or listening on a different port.
Related Developer Errors
Fix "Error: listen EADDRINUSE: address already in use :::3000"
Fix "Error: listen EADDRINUSE: address already in use :::8080"
Fix "Port 5173 is in use, trying another one... (Vite Dev Server)"
Fix "Error: listen EADDRINUSE: address already in use :::5000" (Flask / AirPlay)