server error RFC 9110

HTTP 502 Bad Gateway

A gateway or proxy received an invalid response from the upstream server.

What it means

The server you contacted (a proxy, load balancer, CDN, or API gateway) tried to forward your request to another server and got back something it couldn't parse. Common when the app server crashed mid-response, when nginx can't reach the upstream, or when the upstream returns nonsense.

When servers send it

  • Nginx couldn't connect to upstream Node process
  • Cloudflare couldn't reach the origin
  • AWS ALB got a malformed response from EC2
  • Application server crashed during response generation

What the client does

Retries after a delay. Idempotent requests are safe; POSTs need care.

Common causes

  • Upstream server is down
  • Upstream server crashed while handling the request
  • Upstream is overloaded and closing connections
  • Network issue between proxy and upstream

How to fix it

  • 1.Check upstream server health
  • 2.Check the proxy logs for the specific upstream error
  • 3.For Cloudflare 502s: check origin health
  • 4.Increase upstream timeout if the upstream is just slow

Similar codes

← All HTTP status codes · HTTP status cheat sheet · HTTP headers reference