502 Bad Gateway is a HTTP status code that indicates bad communications between the web server and secondary outbound services needed to process requests with those failure responses propagating to the client.

Here are some reasons why a 502 Bad Gateway HTTP status code may be returned:

  • The web server is receiving an invalid response from an upstream proxy server, load balancer, or other intermediary it tries to communicate with in order to process the request.
  • There is a misconfiguration in intermediate proxy, load balancing, or caching layers causing incorrect responses back to the web server that prevent generating a valid customer-facing response.
  • Security filtering mechanisms like WAFs or DDoS protection services are incorrectly blocking legitimate requests received by the proxy/gateway and sending blocks or errors to the web server.
  • The application server is timing out waiting on a response from a slow backend database, legacy system, or external service dependency needed to construct the final response. The backend errors are bubbling up.
  • Capacity limits are hit on intermediary infrastructure like proxies and gateways causing them to start serving failures which cascade to the origin servers.