Your next big idea starts with a name. Find yours
The blogWebsites & Hosting
THE NAMESILO BLOG

How to Fix the 502 Bad Gateway Error

Illustration of a 502 Bad Gateway error showing failed communication between gateway and origin server

A 502 Bad Gateway error occurs when one server on the internet receives an invalid response from another. This usually means your web host's origin server is overloaded, down, or misconfigured. To fix it, clear your browser cache, temporarily disable your CDN (like Cloudflare), and check your host's server status or error logs.

What Is a Gateway?

A gateway is any server that sits between your visitor and your actual website. When you see 502, the gateway tried to contact your origin server and failed.

Error Code

What It Means

Where the Problem Is

500 Internal Server Error

Bad code or script crashed

Your website's code

502 Bad Gateway

Gateway got invalid response

Communication between servers

503 Service Unavailable

Server temporarily overloaded

Your hosting server

504 Gateway Timeout

Gateway waited too long

Slow origin server response

The key distinction: 500 errors mean your code broke. 502 errors mean servers couldn't communicate, your code might be fine.

Common gateways include CDNs (Cloudflare), reverse proxies (Nginx), load balancers, and caching layers. Any of these can report 502 when the origin server misbehaves.

Root Cause 1: Overloaded Origin Server

The most common cause, your hosting server can't handle requests.

Why this happens:

  • Traffic spike exceeds resources
  • Shared hosting neighbor consuming CPU/memory
  • PHP workers exhausted
  • Database server overloaded

Shared hosting vulnerability: On shared plans, another site's traffic spike can starve your site, triggering 502 errors.

Fix: Wait for traffic to subside, upgrade hosting, or check the host status page for outages.

Root Cause 2: CDN or Firewall Misconfiguration

If you use Cloudflare or another CDN, they may be the "gateway" reporting the error.

Common CDN triggers:

  • Origin IP address changed but CDN not updated
  • SSL mode mismatch (Cloudflare set to Full but origin has no certificate)
  • Firewall blocking CDN IP addresses
  • Origin server rejecting proxy connections

Quick test: Pause Cloudflare (or bypass CDN via DNS). If the site loads, the problem is CDN configuration, not your server.

Cloudflare-specific: Check SSL/TLS settings. "Full (Strict)" requires a valid origin certificate. Mismatch causes 502.

Implementation Steps: Systematic Troubleshooting

Step 1: Refresh and wait 2-3 minutes. Sometimes 502 is temporary.

Step 2: Clear browser cache or test in incognito mode.

Step 3: Check the host status page for reported outages.

Step 4: Bypass CDN, pause Cloudflare or point DNS to origin IP. If the site loads, fix CDN settings.

Step 5: Check error logs in cPanel (Metrics → Errors) for PHP errors or timeouts.

Step 6: WordPress: Rename /wp-content/plugins/ via FTP to disable all plugins. Re-enable one by one.

Step 7: Contact host with timestamps if nothing else works.

Common Mistakes

Assuming it's DNS: 502 is a server communication error, not a DNS resolution failure. Changing nameservers won't help and may break things further.

Ignoring the CDN layer: If Cloudflare shows the error, the problem might be Cloudflare configuration, not your host.

Blaming your code immediately: Unlike 500 errors, 502 often indicates infrastructure issues, not code bugs.

Not checking logs: Error logs reveal the actual failure. Guessing wastes time.

What This Means for You

Persistent 502 errors often signal hosting resource limits. NameSilo Hosting offers scalable plans, upgrade to prevent resource exhaustion during traffic spikes.

Starting fresh? Register your domain and choose hosting that matches your expected traffic.

Frequently Asked Questions

What causes a 502 Bad Gateway? 

Gateway received invalid responses from origin, usually overload or misconfiguration.

Is a 502 error my fault or the server's? 

Usually server or infrastructure, not your code.

How do I fix a 502 error in WordPress? 

Check logs, disable plugins, verify CDN settings.

Does clearing cache fix a 502 error? 

Sometimes, if seeing a cached error page.

How long does a 502 error last? 

Minutes to hours, depending on cause.

Why does Cloudflare show a 502 error? 

Origin server down or SSL misconfigured.

Is my website down if I see a 502? 

For visitors, yes.

How do I check my server error logs? 

cPanel → Metrics → Errors.

WRITTEN BY

NameSilo Staff

The NameSilo staff of writers worked together on this post. It was a combination of efforts from our passionate writers that produce content to educate and provide insights for all our readers.