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

A 502 Bad Gateway resembles a busy signal on the web. It points to a problem with the website’s server rather than your computer or internet connection.

Cloudflare can also trigger a 502 Bad Gateway error when it cannot reach the origin server or its own services are down. The screenshot below shows the error.

502 Bad Gateway Cloudflare Error

The error is temporary, though your hosting provider and website setup can make it recur frequently.

What causes a 502 Bad Gateway Cloudflare error, and which fixes can you try?

Start by identifying the cause.

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.

A comparison may make that explanation clearer.

(Or click here to go straight to the fixes for this 502 Bad Gateway Cloudflare error)

Visiting a website is like calling a friend: your browser contacts the website’s server, which answers by sending information back.

With Cloudflare on your website, the request passes through Cloudflare before reaching the client.

You receive a 502 Bad Gateway error if Cloudflare cannot establish a valid connection with your website’s origin web server.

The error concerns the server side, but a Cloudflare outage or incorrect configuration can also cause it.

Different Variations of a 502 Bad Gateway Error

Your web server and browser determine which 502 error you see. These versions 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

Websites can customise the appearance of a bad 502 gateway error.

Each version says that the intermediary server did not receive a valid reply from the website’s main server.

Causes for a Cloudflare 502 Bad Gateway Error

This error has two possible sources:

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

Usually, the website’s server is overloaded or has a connection problem that takes it offline temporarily.

On a WordPress website, excessive MySQL connections or low PHP memory limits can cause requests to time out. The website then loads slowly and returns 502 errors.

Other causes of a bad gateway error include incorrect DNS records or a firewall blocking requests. Failed services such as PHP-FPM or caching can cause it, as can WordPress plugin/theme conflicts.

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

A 502 Bad Gateway error usually concerns the server’s response, though Cloudflare can cause it too. Try the following fixes to get your website running again.

1. Clear Your Cache And Reload The Page

Being told to reset your modem or restart your computer can be frustrating.

IT staff suggest it because it is the most common and easiest fix.

The cause of Cloudflare-related 502 Bad Gateway errors is often a temporary connection problem.

Try waiting 5 minutes before reloading the page; that may resolve the problem.

If the 502 bad gateway error remains, clear your browser cache and reload once more.

Use Ctrl + F5 to clear the browser cache in Windows and Linux browsers. For Chrome and Safari on Mac, use Cmd + Shift + R.

This “hard refresh” shortcut bypasses the cache for the current page. The site will load again if a temporary connection issue caused the error.

2. Check Your DNS Servers

DNS problems can cause 502 bad gateway errors too.

After changing your web host or moving to a different IP address, allow 24 hours for the DNS changes to resolve.

Try a third-party DNS server, such as Google DNS, to see whether it resolves the 502 error.

3. Check Your Web Hosting

The most common cause of a Cloudflare 502 Bad Gateway error is a hosting server going down. Shared hosting is particularly prone to this because servers terminate processes that take too long.

Cloudflare responds with its branded HTTP 502 bad gateway error in that situation.

502 Bad Gateway Cloudflare Error

Contact your hosting provider and ask them to check that the web server is working correctly.

A sudden traffic increase can also crash the web server. The temporary overload breaks the connection between the server and Cloudflare.

High CPU and memory usage can overload servers as well.

Many hosts also carry out server maintenance without notice. In that case, you can only wait for the host to finish the work.

For a hosting problem, the quickest way to get help is to contact the host’s customer support.

4. Disable Cloudflare Proxy

If your hosting and DNS are working, temporarily disable Cloudflare’s proxy and revisit the site. You can also disable any dedicated CDN (content delivery network) you use alongside Cloudflare.

System outages at Cloudflare and other CDNs are rare, but they can happen.

If disabling the Cloudflare proxy removes the 502 error, contact Cloudflare support to find out what caused it.

The following screen also indicates an error caused by Cloudflare.

Cloudflare Error 502 Bad Gateway

Keep the Cloudflare proxy disabled while troubleshooting, and send Cloudflare support these details:

  • Time and timezone when the error occurred
  • Website URL

Users on the free plan usually receive a Cloudflare reply within 1 to 3 business days. Posting on the Cloudflare community platform may bring a faster response from other users.

Before reporting the problem in the Cloudflare support center, check their System Status to confirm that Cloudflare services are working and the 502 bad gateway error affects only you.

5. Plugin/Theme Conflict in WordPress

Some WordPress plugins and themes can cause 502 errors by running PHP scripts that take too long to finish.

Open “Plugins” in your WordPress dashboard (yourwebsite.com/wp-admin/). Disable all plugins, then check whether the site works.

If that fixes the error, reactivate the plugins individually and reload the site after each one. The plugin that brings back the 502 error is causing the problem.

If you cannot open your WordPress dashboard, use FTP to disable the plugins: rename the “Plugins” folder to something such as “Old_Plugins”.

Once you identify the plugin or theme causing the error, contact its developers to report the problem.

Summary

An unexpected Bad Gateway error can be frustrating. Check that DNS and your web server are working correctly. Server error logs can also help you identify a problem triggered by a recently added application.

For a Cloudflare issue, leave the proxy disabled and open a support ticket.

If these fixes do not work, report the error to your hosting provider. They can investigate from their side and help you resolve it.

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.