The server acting as a gateway received an invalid response from the upstream server.
The server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request. In plain terms, one server asked another server for help, and the response it got back was broken or missing.
A 502 Bad Gateway error occurs when a reverse proxy (Nginx, HAProxy), load balancer, or CDN forwards your request to a backend server that returns a malformed or no response. This is fundamentally a server-to-server communication failure.
The front-facing server (the "gateway") successfully received your request and tried to pass it along to the backend application server. But the backend either crashed, sent back garbage data, or closed the connection unexpectedly.
proxy_pass or upstream block in Nginxsystemctl status php-fpm, pm2 list, or ps aux | grep gunicorn to verify the backend process is alive./var/log/nginx/error.log will show "upstream connection refused" or "upstream timed out" messages.curl localhost:PORT to bypass the proxy and confirm the backend works independently.iptables -L or ufw status to ensure the proxy can reach the upstream port.proxy_read_timeout 300s in Nginx if the upstream needs more time to respond.proxy_pass uses a hostname, ensure it resolves correctly from the proxy server.GET /app/dashboard HTTP/1.1 Host: example.com Accept: text/html
HTTP/1.1 502 Bad Gateway Content-Type: text/html Server: nginx/1.24.0 Date: Thu, 20 Feb 2026 12:00:00 GMT <html> <head><title>502 Bad Gateway</title></head> <body><center><h1>502 Bad Gateway</h1></center></body> </html>
Monitor your website 24/7 and receive instant alerts when 502 errors occur.
Start Free Monitoring