How To Fix A 502 Bad Gateway Cloudflare Error (Fast)

A 502 Bad Gateway is like a busy signal on the web. It means the problem is with the website’s server, not your computer or internet connection.

Sometimes, Cloudflare can also trigger the 502 Bad Gateway error if it cannot reach the origin server or if its services are down. The error looks like this 👇🏻

502 Bad Gateway Cloudflare Error

Though it’s a temporary error, it can appear quite frequently depending on your hosting provider and website setup.

So why does this error occur, and how can you fix a 502 Bad Gateway Cloudflare error?

Let’s find out.

What Does 502 Bad Gateway Cloudflare Error Mean?

A 502 Bad Gateway Error occurs when Cloudflare cannot establish a valid connection with your website’s origin web server. While this error message relates to the server-side (i.e. your web host), it can also happen if Cloudflare service is down or not correctly configured.

Was that a horrible explanation? Sorry, let me try again.

(Or click here if you’re just looking for how to fix this 502 Bad Gateway Cloudflare error)

Think of visiting a website like calling a friend. Your browser “calls” the website’s server. The server “answers” and sends information back to your browser.

But when you’re using Cloudflare on your website, the request is sent to Cloudflare before it reaches the client.

And a 502 Bad Gateway error occurs when Cloudflare cannot establish a valid connection with your website’s origin web server.

While this error message relates to the server-side, it can also happen if Cloudflare service is down or not configured correctly.

Different Variations of a 502 Bad Gateway Error

Based on your web server and browser, you might see a different 502 error, but they all mean the same thing:

  • 502 Bad Gateway
  • Error 502
  • 502 Proxy Server
  • HTTP 502
  • 502 Proxy Error
  • Temporary Error (502)
  • HTTP Error 502 – Bad Gateway
  • 502 Bad Gateway Nginx
  • 502 Server Error: The web server encountered a temporary error and could not complete your request
  • 502. That’s an error
  • 502 Service Temporarily Overloaded

Some websites can also customize how a bad 502 gateway error looks.

But no matter how it’s worded, the message means the same thing: the middleman (server) didn’t get a proper reply from the website’s main computer.

Causes for a Cloudflare 502 Bad Gateway Error

The two possible causes for this error are:

  • 502 status code from the origin web server
  • 502 error from Cloudflare

Most often, this error pops up because the website’s server is too busy or having connection troubles, making it go offline for a bit.

If you have a WordPress website, then too many MySQL connections or low PHP memory limits can lead to request timeout. As a result, the website starts loading slowly and gives 502 errors.

Several other reasons can lead to a bad gateway error—incorrect DNS records, request block by a firewall, service failure (like PHP-FPM and cache services), or plugin/theme conflict in WordPress.

How to Fix a 502 Bad Gateway Cloudflare Error

  1. Clear Your Cache And Reload The Page
  2. Check Your DNS Servers
  3. Check Your Web Hosting
  4. Disable Cloudflare Proxy
  5. Plugin/Theme Conflict in WordPress

When a 502 Bad Gateway error occurs, it’s mostly related to the server-side response, but Cloudflare can also cause this error. So below are a few ways you can apply to fix the problem and get your website up and running.

1. Clear Your Cache And Reload The Page

Little is more frustrating than your IT guy telling you to reset your modem or turn your computer off and on again.

But they do it for a reason: it’s the most common (and easiest) way to fix the issue.

Cloudflare-related 502 Bad Gateway errors often occur due to temporary connection problems.

So simply waiting 5 minutes and reloading the page can do the trick.

If you still see a 502 bad gateway error, then clear your browser cache and reload the page again.

To clear the browser cache, you can hold down Ctrl + F5 for Windows and Linux browsers, and Cmd + Shift + R for Chrome and Safari on Mac.

This shortcut (known as a “hard refresh”) will bypass the cache for the specific page that you’re on, and the site will come back if it’s just a temporary connection issue.

2. Check Your DNS Servers

Sometimes, DNS can also cause 502 bad gateway errors.

If you’ve recently changed your web hosting service or moved to a different IP address, then it’s recommended to wait for 24 hours for the DNS changes to resolve.

You can also change your DNS to any third-party DNS servers like Google DNS to see if that solves the 502 error.

3. Check Your Web Hosting

The most common cause of Cloudflare 502 Bad Gateway error is when the web hosting server is down — especially on shared hostings where servers kill the processes that take too long to complete.

When that happens, Cloudflare returns a Cloudflare branded HTTP 502 bad gateway error.

502 Bad Gateway Cloudflare Error

To fix this, you can contact your hosting provider to make sure that the web server is performing correctly.

Sometimes, a sudden increase in traffic can also cause the web server to crash. When that happens, the server becomes temporarily overloaded, resulting in loss of a connection between the server and Cloudflare.

Servers can get overloaded due to excessive CPU and memory usage as well.

A lot of hostings also put servers into maintenance without any notification. The only way to solve the problem, in this case, is to wait for the hosting to finish the server maintenance.

If the trouble is with the website’s hosting, reaching out to their customer support is your quickest route to a solution.

4. Disable Cloudflare Proxy

If your hosting and DNS is fine, you can disable Cloudflare’s proxy for a while, and then visit the site again. If you’re using a dedicated CDN (content delivery network) in addition to Cloudflare, you can disable that too.

Cloudflare and CDNs can also experience system outages, that rarely happens, but a possible situation.

If the 502 error goes away after you disable Cloudflare proxy, then you will have to contact the Cloudflare support to find out the cause of the issue.

Also, if you see the following screen, then the error is because of Cloudflare.

Cloudflare Error 502 Bad Gateway

To troubleshoot this, you can keep the Cloudflare proxy disabled, and share the following details with Cloudflare support:

  • Time and timezone when the error occurred
  • Website URL

Cloudflare usually replies within 1 to 3 business days to users on the free plan. You can also post your issue on the Cloudflare community platform, where other users might help you faster.

Before raising the problem in the Cloudflare support center, it’s good to check their System Status to make sure that Cloudflare services are working fine, and only you’re facing the 502 bad gateway error.

5. Plugin/Theme Conflict in WordPress

If you’re on a WordPress website, then some plugins and themes can also cause 502 errors when PHP scripts take too long for execution.

To check, go to “Plugins” in your WordPress dashboard (yourwebsite.com/wp-admin/), disable all the plugins, and see if the site works.

If this fixes the error, then activate the plugins one by one and reload the site after each activation. When you see the 502 error, you’ve found the cause of the problem.

But if you can’t access your WordPress dashboard, then you can disable the plugins via FTP by changing the name of the “Plugins” folder to something else (like “Old_Plugins”).

Once you have found the issue causing plugin/theme, you can contact their developers and notify them about the problem.

Summary

Bad Gateway errors are unexpected and can be frustrating. The best way to solve it is to see if the DNS is working fine, and your web server is running properly. You can also check the server error logs to pinpoint the issue triggered by any recently added application.

If it’s a Cloudflare issue, keep the proxy disabled and raise a ticket on their customer support.

Finally, if nothing works, reach out to your hosting provider and let them know about the error. They can identify the problem from their end and help you fix it as well.

If you’re looking for (free) tips to optimize your site speed with Cloudflare and rank higher on Google, you can follow me on Twitter 👉🏻 @bitofseo.

Please DM me if you have any questions about this Cloudflare article (or have some feedback to make it better 😄️).

About Jake Sacino

After working as an engineer and consultant for a bunch of big companies, Jake now works as a full-time SEO & software engineer.