502 Bad Gateway

How to Fix “502 Bad Gateway”

HTTP Status Error 📄 Chrome, Firefox, Edge, Safari
⚡ Quick answer

A 502 Bad Gateway error means a server acting as a gateway or proxy received an invalid response from an upstream server. The front-end server (like Nginx or a CDN) is working, but the back-end application server it's trying to talk to isn't responding correctly.

First, check if your internet is working and what your current IP address is:

🔍 Check My IP Address →

What Causes the “502 Bad Gateway” Error?

Modern websites use layers: a front-end server (Nginx, CDN, load balancer) passes requests to a back-end application server (PHP-FPM, Node.js, Python). 502 means the front-end got garbage or nothing from the back-end. Causes: back-end server crashed, is overloaded, or returned malformed data; the back-end is being restarted during deployment; network issues between the servers; or a Cloudflare/CDN routing problem.

How to Fix It — 5 Methods

1 Wait and Refresh

502s are frequently caused by server restarts during deployments or brief overloads. Wait 30–60 seconds and press F5. If the site is undergoing maintenance or a high-traffic spike, this often resolves on its own within minutes.

2 Clear Browser Cache

Ctrl+Shift+Delete → All time → Cached images + Cookies → Clear. Then try a hard refresh with Ctrl+Shift+R to ensure you're not hitting a cached error response.

3 Try a Different DNS Server

Sometimes 502 errors are caused by DNS routing you to a dead server in a CDN's pool. Switching to a different DNS server (8.8.8.8 or 1.1.1.1) may route you to a different CDN node that is working. Flush your DNS after switching: ipconfig /flushdns.

4 Disable VPN or Proxy

VPNs and proxies add an extra hop. If the VPN server is having routing issues to the destination, you may see 502. Disconnect from the VPN and connect directly to see if the error persists.

5 If You Own the Site: Restart the Application Server

SSH into the server and restart your application process. For PHP-FPM: sudo systemctl restart php8.1-fpm. For Node.js (PM2): pm2 restart all. For Gunicorn/Python: restart the process. Also check back-end logs for crash reasons before restarting.

🔒
Some errors are caused by ISP blocks or network restrictions
A VPN bypasses them instantly by routing through a different server.

Fixed it? Visit tools.examineip.com to confirm your IP address and connection are working correctly.

Frequently Asked Questions

What's the difference between 502 and 504?
502 means the upstream server responded with an error or garbage. 504 means the upstream server didn't respond at all within the timeout window. Both indicate back-end problems, but 504 suggests a slower failure (timeout) vs 502 (immediate bad response).
Cloudflare is showing me a 502 — is it Cloudflare's fault?
Usually no. Cloudflare shows a branded 502 page but the error is almost always the origin server (the actual website server) failing to respond to Cloudflare's request. If Cloudflare itself were the problem, you'd see a Cloudflare-specific error with a Ray ID.
Is 502 always a server-side problem?
Yes. 502 is entirely server-side. There's nothing on your end causing it — the servers are miscommunicating between themselves. You can only wait or try the cache/DNS workarounds.

Learn More About IP Addresses & Privacy

← Back to the complete guide: Internet Errors Hub

Last updated: April 2, 2026 • Report an error

Scroll to Top