What it means
A gateway or proxy received an invalid response from the upstream server it forwarded the request to.
Common causes
- The app server crashed or is not listening (wrong port or socket)
- Upstream closed the connection or sent malformed headers
- PHP-FPM, Gunicorn or Node process restart
How to fix it
As a client or visitor
Retry after a moment; it is usually temporary. If it persists, the site's backend is down.
As the site or API owner
Check that the upstream process is running and listening on the address the proxy uses, and read the proxy's error log for the exact upstream error.
Example response
HTTP/1.1
HTTP/1.1 502 Bad Gateway
Date: Tue, 07 Oct 2025 09:30:00 GMT
Server: nginx
Content-Type: text/html
Content-Length: 0 Specification
FAQ
› How do I fix 502 Bad Gateway in nginx?
Check the upstream (is the app running, correct proxy_pass address/socket) and the nginx error log; restart the app server if it crashed.
› 502 vs 504?
502: upstream answered with garbage or closed the connection. 504: upstream did not answer in time.