502 Bad Gateway
The server you reached is a middleman (a proxy, CDN or load balancer). It forwarded your request to the real server behind it and got a broken or empty response back.
Quick checks
- Reload after a minute: 502s are often brief, during deploys or restarts.
- Check whether the site is down for everyone (its status page or social accounts).
- Try another network or device to rule out a local proxy or VPN.
If you’re visiting the site
Wait and reload
- Press ⌘R (Mac) or F5 (Windows) after a minute or two.
- A hard reload (⌘⇧R) skips cached copies of the error page.
Rule out your side
- Disconnect VPNs and proxies; some corporate proxies return their own 502.
- Try another browser or a private window.
- Flush DNS on your Mac (
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder) in case the site recently moved.
If you run the site
Check the upstream (application) server
- Is the app process running? Check
systemctl status, Docker or your process manager, and look for crashes or out-of-memory kills. - Does it listen where the proxy expects? Compare the proxy's
proxy_passor upstream address and port with the app's listening address.
- Is the app process running? Check
Read the proxy's error log
- nginx:
/var/log/nginx/error.logshows lines likeconnect() failed (111: Connection refused) while connecting to upstreamorupstream prematurely closed connection. - Refused means the app isn't listening; prematurely closed means it crashed or hit a limit mid-request.
- nginx:
Check limits and timeouts
- Large headers or cookies can exceed proxy buffers (
proxy_buffer_sizein nginx). - PHP-FPM, Gunicorn and similar pools may be exhausted under load; raise workers or fix slow requests.
- Large headers or cookies can exceed proxy buffers (
Behind a CDN
- Cloudflare shows its own codes (520–526) for origin problems; check the origin directly, bypassing the CDN, to see if it answers.
Still not working?
Visitors can't fix a 502: it's between the site's own servers. If it persists for hours, contact the site.
Owners: test the upstream directly from the proxy host with curl -v http://127.0.0.1:PORT/ to separate an app failure from a proxy misconfiguration.
See what’s happening
For developers running a local reverse proxy, LightAtom's Ports view shows whether the upstream app is listening and on which address and port.
Frequently asked questions
Is 502 Bad Gateway my fault?
Almost never. It means the site's own servers can't talk to each other properly. Rarely, a corporate proxy or VPN returns a 502; try another network to check.
What is the difference between 502 and 504?
502 means the upstream server returned an invalid response or closed the connection. 504 means it didn't respond in time. Both come from a gateway or proxy.
How long does a 502 error last?
Usually seconds to minutes, during a restart or deployment. Longer outages mean the backend is down and needs the site's team to fix it.
Can clearing my cache fix a 502?
Only if your browser cached the error page. A hard reload (⌘⇧R) rules that out; otherwise the fix is on the server.