Fixing the 502 Bad Gateway Error in WordPress

On WordPress, you never know what error can be encountered. These are quite confusing and difficult to fix for a person who is not familiar with tech. The most common errors people get when using WordPress are the white screen and the impossibility of establishing a database connection. Both are easy to fix. Another one is the 502 Bad Gateway error, and people receive it so often that creating a guide to how to fix it seems to be a good idea.

The 502 Bad Gateway error can be difficult to troubleshoot because of a multitude of reasons. First of all, you need to find the source of the problem. Then, you need to change the settings to put your website back on its feet. Not all WordPress users are familiar with solving this issue, so this guide will definitely come in handy. Before fixing the 502 error, you need to understand why it occurs. Learn below more about this topic in this article created by our team at wpDataTables.

Table of Contents

  • Causes of 502 Bad Gateway error
  • Fixes for the 502 Bad Gateway error

Causes of the 502 Bad Gateway error

The reasons behind the 502 Bad Gateway errors are:

  • The presence of a bug in the PHP scripts
  • Server overload
  • Router issues
  • Aggressive browser cache
  • Domain Name System issues
  • The main server is down or has no connectivity
  • The requests are blocked by a firewall

To understand what does 502 Bad Gateway mean, you should know a few things about other 500 status codes as well. These are all gateway errors that indicate that the request was accepted, but a problem occurs with fulfilling the request because of the server.

So, what is a 502 error ultimately? The server regardless of its type (gateway or proxy) will receive an invalid response from another inbound server. This causes the 502 error. Sometimes, the error goes away by itself after a couple of minutes and some page refreshes, but this is not an often situation. If you are part of the unlucky cases, continue reading to learn how to fix it.

Fixes for the 502 Bad Gateway error

Reloading the page

A 502 Bad Gateway fix that you should try before anything else is simply reloading the website. You can reload the website by clicking on the refreshed website or pressing F5. You should wait for a minute or two between refreshes to see if anything happens.

Usually, the 502 error solves by itself because the cause behind the Bad Gateway issue was caused by server overload. By waiting a few moments or even changing the browser, the problem will be solved. To make sure that the website is down because of server overload, you can access This is a website that tells whether it is a problem on your side or it is a server problem.

Clearing cache

The second 502 Bad Gateway error fix that is easy and rapid is clearing the cache. If refreshing doesn’t do anything, it’s time to make the web browser forget what it knows about that page and load the updated data from it. Pressing CTRL + F5 (Windows) or CMD + Shift + R (Mac) will remove the cache from the page you are on. You can also clear cache from the browser’s settings, where you have advanced options to choose from.

Disable CDN/Firewall

The CDN, short for Content Delivery Network, can be the cause of the 502 Bad Gateway error. CDN is used to deliver web content in a faster manner, but it can be the reason why your website crashes on load because of the additional checkpoint between the server and browser that it adds. The same goes for firewalls. If you use any of these, it would be recommended to temporarily disable them and see whether the problem is fixed or not.

Once disabled, there is no checkpoint that needs to be reached between the server and the browser, which means that the 502 Bad Gateway error should be solved. In case you don’t know much about CDN, you can contact your service provider for support. Enable CDN again once the problem is solved and see if the website acts as supposed to.

Check plugins and themes for errors

After refreshing the page, clearing the cache and disabling CDN, the website should work fine. If you still receive a 502 Bad Gateway error, then you will need to check the plugins and themes you are using. There are two situations in this case:

  • You can access your admin dashboard. In this case, you simply need to access Plugins and select Deactivate. Once you deactivated all the plugins, refresh the page and see if you receive the error. If not, the problem is one or more of the plugins you were using. To find out which, you need to activate the plugins one by one following the steps mentioned earlier and find the misbehaving one. When the 502 Gateway error returns, you will know that the plugin you just activated is faulty. Then, you can start a support ticket in WordPress or contact the plugin’s developer directly to get the issue fixed.
  • You can’t access your admin dashboard. If this is your situation, you need to deactivate the plugins by using FTP or Control Panel. Go to your WordPress root directory and look for wp-content. Navigate to plugins and rename the folder so that your website can no longer access it. Then, check if your website works. If yes, this is the cause behind the 502 Bad Gateway error.

The same goes for themes.

Check logs for errors

You can generate WordPress logs and check them for errors in order to find out why the 502 Bad Gateway appears. Find your wp-config.php file and paste this piece of code in it:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Running into a PHP Timeout issue

If the PHP process reaches its “max_execution_time” that is configured in your server, it will stop working and generate a 502 Bad Gateway error. This is a common problem that can simply be solved by elevating the values.

You don’t have to do this by yourself. Contact the WordPress host and ask for an increase in the “max_input_time” that was initially set for the website. This might take longer to fix, but it is the proper solution if nothing else works.

Hosting server issues

Finally, if all the steps mentioned in this guide fail to work, the 502 Bad Gateway error can be caused by your hosting server. The only way to tackle this situation is to contact the support team and let them know about the issue you encounter. Most WordPress hosting companies can fix such issue quite fast. It all depends on the company you chose. This should solve the 502 Bad Gateway error for good.

FAQ on the 502 bad gateway error in WordPress

What’s a 502 Bad Gateway Error, anyway?

Oh man, so, a 502 Bad Gateway Error? It’s basically the web’s awkward way of saying, “I tried to get a response from another server or proxy, but something went wrong.” Think of it like calling a friend, but their phone is off. You know there’s an issue, but you’re not 100% sure what.

Does it always have to do with WordPress?

Nope, not really! While our dear WordPress does get its fair share of the blame, the truth is this error can pop up on any platform or web server, whether it’s Nginx or Apache. But given how many of us use WordPress, it’s often the first place we notice it.

So, is it my browser or is it the server?

Alright, here’s the deal: most of the time, the problem’s on the server side. But occasionally, it could be your browser cache playing tricks on you. A quick cache clear might just do the trick, but if that doesn’t help, it’s time to dig deeper into server issues.

Could my plugins be causing the mess?

Ah, WordPress Plugins. Can’t live with ’em, can’t live without ’em, right? Yes, sometimes they’re the culprits. If two plugins don’t play well together, or if there’s a bad update, they could totally cause a 502 error. Always worth checking!

What’s this .htaccess thing I keep hearing about?

Okay, so the .htaccess file? It’s a critical config file for Apache web servers. If it’s misconfigured? Boom, problems galore. For WordPress users, it can handle permalinks and other important tasks. Mess with it without caution, and you might end up seeing our infamous error.

I’ve heard CDN can be a cause. Is that true?

Totally! CDN, like Cloudflare, are middlemen. They deliver your website’s content quickly to users all over. But if there’s an issue between your original server and the CDN? Yep, you guessed it, that pesky 502 error might just show up.

How do I get in touch with Tech Support?

Getting in touch with Tech Support from your hosting company is a smart move. They’re the pros. They’ve got the tools and the know-how to figure out if it’s a server timeout, a firewall issue, or something else entirely.

Does restarting my server help?

Sometimes, it’s like the old “turn it off and on again” trick. Restarting your server can genuinely solve the problem, especially if it’s due to services like PHP-FPM. So if you’ve got the power, give it a shot!

If it’s not WordPress or the server, what else can it be?

Oh, there’s a laundry list! Database Connection issues, Firewall configurations, or even external services that your site relies on. The web’s interconnected, and sometimes, one weak link can cause a chain reaction.

Any last-ditch efforts I can try?

Honestly, when all else fails, my go-to is troubleshooting. Delve into logs, check recent changes, or ask a friend with some tech-savvy. The web community is huge, and someone’s probably faced (and solved) the same issue before!


If you enjoyed reading this article on fixing the 502 bad gateway error, you should check out this one about how to fix WordPress white screen of death.

We also wrote about a few related subjects like how to fix err_ssl_version_or_cipher_mismatch, how to fix WordPress not sending email, how to fix too many redirects, fixing WordPress http error when uploading image and how to fix 504 error.

Milos Timotic
Milos Timotic

Full Stack Web Developer

Articles: 41