HTTP 502 Bad Gateway

Plain-English meaning

A gateway/proxy got an invalid response from upstream.

Why it happens

Gateway connected upstream, but response was malformed, reset, or closed early.

Common causes

  • Upstream crashed mid-response
  • Proxy protocol mismatch (HTTP/HTTPS)
  • Wrong upstream host or port
  • Unhealthy load-balancer target

What to check first

Read proxy error logs, test upstream directly from gateway host, and verify TLS/keepalive settings between tiers.

How to fix it

Stabilize upstream service, correct proxy protocol/port, and tighten health checks to remove bad targets quickly.

Example signal

upstream prematurely closed connection while reading response header

Related links

404 · 429 · 500 · 502 · 503 · 504 · Cloudflare 522 · Nginx 499 · ERR_CONNECTION_REFUSED

Client errors hub · Server errors hub · Comparison pages · Homepage