502 Bad Gateway: What It Means and How to Fix It
Appears on: All browsers. 502 Bad Gateway is an HTTP status code returned by a proxy, CDN, or load balancer when the upstream origin server returns an invalid or no response. It is almost always a server-side problem — the most a visitor can do is reload and wait.
What 502 Bad Gateway actually means
In a modern web architecture, your browser connects to a proxy layer (Nginx, Cloudflare, AWS ALB) which forwards requests to an origin server (a Node.js app, PHP process, or Python service). 502 fires when the proxy receives a response it can't interpret — the origin sent garbage, crashed mid-response, or refused the connection. The proxy is working; the backend isn't. This is distinct from 504, where the backend simply doesn't respond in time.
Most likely causes (ranked)
- Application server crashed or ran out of memory (PHP-FPM worker died, Node.js uncaught exception)
- Upstream server overloaded — high traffic spike causing connection refusals
- Database timeout causing the app to return an error the proxy can't forward cleanly
- Nginx or Apache misconfiguration — proxy_pass pointing to wrong port or socket
- CDN routing issue — Cloudflare or similar CDN failing to reach origin
What to try as a visitor
Step 1: Hard reload the page
Press Ctrl+Shift+R (Windows/Linux) or Cmd+Shift+R (macOS). Transient 502s from brief application restarts or traffic spikes often clear on the first retry.
Step 2: Clear browser cache
Press Ctrl+Shift+Delete → Advanced → check Cached images and files → Clear data. A previously cached 502 response can persist and serve the error even after the server recovers.
Step 3: Try a different network or DNS
Switch to a mobile hotspot, or change your DNS to 1.1.1.1 (Cloudflare) or 8.8.8.8 (Google). CDN edge node routing issues occasionally affect certain ISPs or DNS resolvers differently.
Step 4: Check the site's status page
Visit downdetector.com or the site's own status page (typically status.[sitename].com). If an incident is posted, the 502 is confirmed server-side and there is nothing more to do client-side — wait for recovery.
Step 5: For site operators — check backend logs
In Nginx: /var/log/nginx/error.log. Look for connect() failed or upstream prematurely closed connection. Verify your application server process is running (systemctl status php-fpm / pm2 list), check database connectivity, and confirm proxy_pass targets the correct address and port.
Frequently Asked Questions
Is 502 my fault or the server's fault?
Almost always the server's. 502 means the gateway (Nginx, CDN, load balancer) received a bad or empty response from the application backend. As a visitor, refreshing and waiting is your only reliable option. The error clears when the site operator fixes their backend.
What is the difference between 502 and 504?
502 Bad Gateway: upstream responded with an invalid or error response (crashed, returned garbage). 504 Gateway Timeout: upstream didn't respond within the allowed time (too slow or unreachable). Both originate from a proxy layer, but 502 means a bad response arrived and 504 means no response arrived.
Related Guides
504 Gateway Timeout
When the upstream server is too slow or unreachable rather than returning a bad response.
503 Service Unavailable
When the server itself reports it is down for maintenance or overloaded.
ERR_HTTP2_PROTOCOL_ERROR
Protocol-level connection failures that can accompany 502 errors.
This Site Can't Be Reached
When no response arrives at all — DNS, firewall, and connectivity failures.