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.
- Bypass CDN temporarily to hit origin directly and compare status codes.
- Increase or align timeouts between proxy and app if logs show slow queries.
- 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
Isolate upstream
- Bypass CDN temporarily to hit origin directly and compare status codes.
- Increase or align timeouts between proxy and app if logs show slow queries.
- Verify upstream health checks and pool membership in your load balancer.
Related
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.
Fix related issues
Still stuck? Try these related fixes next.
- Kubernetes CrashLoopBackOffThe container exits repeatedly—check logs, probes, and resource limits.
- Heroku H10 — app crashedThe web process exited; Heroku serves an error page. Logs show the real exception.
- Netlify — page not foundThe deploy exists but no asset matches the path—often SPA routing or a missing file in publish dir.
- Vercel — deployment not foundThe deployment URL or project alias does not exist or was removed.
- Cloudflare 525 — SSL handshake failedCloudflare could not complete TLS with your origin—cert mismatch, wrong port, or TLS version.
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
