5xx

502 Bad Gateway

The server acting as a gateway received an invalid response from the upstream server.

What is HTTP 502?

This status code indicates that the server, while acting as a gateway or proxy, received an invalid or unexpected response from an upstream server it accessed while trying to fulfill the request. The problem is not with the gateway itself but with the backend server behind it. This is common in architectures with reverse proxies, load balancers, or CDNs in front of application servers.

Defined in RFC 9110

Common Causes

  • The upstream application server crashed, is not running, or is not responding
  • The backend server returned a malformed or incomplete response to the proxy
  • Network connectivity issues between the proxy or load balancer and the backend server
  • The upstream server's process ran out of memory or hit a resource limit

How to Fix

  • Check that the upstream application server is running and healthy
  • Review the proxy or load balancer error logs for details about the invalid response
  • Verify network connectivity between the proxy and the backend server
  • Restart the upstream server if it has crashed or become unresponsive