Runs in your browser. Your files and text never leave your device - nothing is uploaded.
5xx Server Error
What it means
A server acting as a gateway or proxy received an invalid response from the upstream server it was trying to reach.
| Property | Detail |
|---|---|
| Status class | 5xx Server Error |
| Defined in | RFC 9110, Section 15.6.3 |
| Cacheable by default | Only with explicit caching headers: a cache stores it when the response carries Cache-Control (max-age, s-maxage or public) or Expires. |
| Who needs to act | The site owner or hosting provider. |
What does HTTP 502 Bad Gateway mean?
HTTP 502 Bad Gateway means a server acting as a gateway or proxy, such as nginx, a load balancer or a CDN, received an invalid response from the upstream server behind it. The proxy itself is working; the application server it forwards to crashed, refused the connection, or replied with something that was not valid HTTP.
How 502 Bad Gateway works
A 502 always involves at least two servers. The one that answers you, a reverse proxy, load balancer or CDN edge, tried to pass the request to an upstream application and got nothing usable back. The quickest clue is the proxy's error log. nginx, for example, logs 'connect() failed (111: Connection refused) while connecting to upstream' when the application is not listening, and 'upstream prematurely closed connection' when it died mid-response. A 502 often appears briefly during deploys, when the old process has stopped and the new one is not yet accepting connections.
Example 502 request and response
GET /dashboard HTTP/1.1
Host: app.example.com
HTTP/1.1 502 Bad Gateway
Server: nginx
Content-Type: text/htmlnginx answered, so the front door is up. The application behind it is what failed.
What causes a 502 Bad Gateway
- The application process, such as Node.js, PHP-FPM or Gunicorn, crashed or is not running.
- The proxy points at the wrong host, port or socket path.
- The application was killed in the middle of a request, for example by the out-of-memory killer.
- Response headers larger than the proxy's buffers.
- Restarts during deploys with no overlap between the old and new processes.
How to fix a 502 Bad Gateway
If you are a visitor
- Wait a minute and reload; 502s during deploys or restarts usually clear quickly.
- Check the site's status page, or try another network if it persists.
If you run the site
- Read the proxy's error log first; it names the upstream failure.
- Confirm the application is running and listening on the host, port or socket the proxy expects.
- Check application logs and memory usage for crashes at the same timestamp.
- Use rolling or zero-downtime deploys with health checks, so the proxy only sends traffic to ready instances.
502 and SEO
Google handles 502 like other server errors: it temporarily slows crawling, keeps indexed URLs for the time being, and eventually drops URLs that keep failing. Brief 502s during a deploy are harmless; recurring ones are worth monitoring.
Related status codes
- 504 Gateway Timeout: The upstream did not answer in time, rather than answering badly.
- 503 Service Unavailable: The server is up but deliberately not taking requests.
- 500 Internal Server Error: The application itself reported an error, with no proxy in the way.
Frequently asked questions
A server acting as a gateway or proxy received an invalid response from the upstream server it was trying to reach.
A backend server crashed, is overloaded, restarted, or a proxy/load-balancer configuration issue between it and the client.
Retry the request after a short wait. If you run the server, check the backend's logs and health, and the proxy/load-balancer configuration.
Both come from a proxy or gateway. A 502 means the upstream server returned an invalid response or refused the connection. A 504 means no response arrived within the proxy's time limit.
Sources
Other 5xx Server Error codes
Reviewed by Raja Jahangir · Last reviewed: October 7, 2026
