Fixing the 502 Bad Gateway Error in WordPress

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 downforeveryoneorjustme.com. 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.

If you enjoyed reading this article about fixing 502 Bad Gateway error, you should read these as well:

Up Next:

How to Host a Website: All Steps Explained

How to Host a Website: All Steps Explained