A gateway or proxy got an invalid response, or no response, from the upstream server.
502 Bad Gateway is generated by something in the middle, such as nginx, a load balancer or a CDN, when the server behind it failed: the connection was refused or reset, or the reply was not valid HTTP. The application itself usually never logged the request, so look at the proxy's error log first.
connect() failed (111: Connection refused) while connecting to upstream, meaning the app server (Gunicorn, PHP-FPM, Node) is down or on a different port or socket.upstream prematurely closed connection, meaning the app crashed or was OOM-killed mid-request.upstream sent too big header (raise fastcgi_buffer_size / proxy_buffer_size).ss -ltnp).server.keepAliveTimeout = 65000 behind ALB).dmesg, kubectl describe pod) and crash loops.| Header | Role |
|---|---|
Server | Tells you which proxy generated it (nginx, awselb/2.0, cloudflare). |
HTTP/1.1 502 Bad Gateway
Server: awselb/2.0
Content-Type: text/html
Content-Length: 122