Error fix

How to fix “502 Bad Gateway

A proxy or edge server received an invalid or empty response from an upstream server.

Updated Apr 20, 2026

Tools that help with this

Fastest fix

Start here first. Step 1 fixes most cases—then work down the list.

  1. Bypass CDN temporarily to hit origin directly and compare status codes.
  2. Increase or align timeouts between proxy and app if logs show slow queries.
  3. Verify upstream health checks and pool membership in your load balancer.

Why this works

These steps work because it removes the most common source of mid-request resets: VPN/proxy interference, and it helps isolate CDN edge issues vs your origin server.

What this means

Something between the client and your app (CDN, load balancer, nginx) could not complete a valid response from the next hop.

Common causes

  • Origin down or restarting

    Container cold start, crash loop, or TCP connection refused to the app port.

  • Protocol/timeouts

    TLS mismatch, keepalive issues, or upstream slower than proxy timeout.

Step-by-step fix

  1. Isolate upstream

    1. Bypass CDN temporarily to hit origin directly and compare status codes.
    2. Increase or align timeouts between proxy and app if logs show slow queries.
    3. Verify upstream health checks and pool membership in your load balancer.

Also see: 502 — browse the HTTP status hub.

FAQ

502 only for some users?
Often a single bad origin in a pool or regional edge issue—check per-POP or per-AZ metrics.
502 after deploy?
Roll back, verify listen address/port, and health check paths on the new version.
502 vs 504?
502 is often bad/empty response; 504 is usually a timeout waiting for upstream.

Still stuck? Try these related fixes next.

Edit your error

Tweak the message and run again—we'll match an existing fix or generate a new page.

Original error message
502 Bad Gateway
Fix another errorHTTP status codesURL status checkerRedirect checkerAll tools