Explained: How to Fix the 502 Bad Gateway Error in WordPress?

You must have come across the very annoying 502 bad gateway error on a WordPress site at least once. Do you want to know how you can solve this frustrating issue? Well, if yes then you are in the right place.

Today we will talk about the 502 bad gateway error in WordPress, how you can troubleshoot it and how to solve this problem. 

What Is 502 Bad Gateway Error?

502 bad gateway error is an HTTP status code that appears when the internet server does not receive a valid d response from another server. In other terms, a 502 bad gateway error is a technical error that occurs when the proxy (gateway) server is unable to receive a valid response from the upstream server. Thus, miscommunication between different servers causes a 502 bad gateway error.

This means that when you see a 502 bad gateway error on any website then the original server has sent an invalid response to the server connected to the internet which acts as a proxy.

Trying to identify the problem and finding out what caused it could be tricky. However, there are many troubleshooting procedures that we can follow to get to the root of the 502 bad gateway error which can help us solve it.

Variations in 502 Bad Gateway Error

The 502 bad gateway error can be of different sorts due to the various operating systems, internet browsers and web servers. Here are the most common variations of the 502 bad gateway error:

  • HTTP 502
  • 502 bad gateway
  • HTTP Error 502 – Bad Gateway
  • Error 502
  • 502 proxy error
  • 503 service temporarily overloaded
  • A blank white screen
  • 502 Server Error: Server encountered a temporary error and cannot complete your request.
  • 502. That’s an error. The server has encountered a temporary error and could not complete your request. Please try again in 30 seconds.

Now that you know what a 502 bad gateway error is and what its different variations are, let’s move on to see how we can fix this error.

Fixing 502 Bad Gateway Error

As stated earlier the 502 bad gateway error is usually an issue with the server or network. However, sometimes it can also be an issue from the client’s side.

We will look at five common causes of the 502 Bad Getaway Error and how you can solve them:

Check Server

The 502 Bad Gateway Error shown in the picture below is usually caused by an issue with the server.

In this case, the server is running nginx. WordPress is running on PHP and MySQL. So, in nginx we need to check how PHP files are processed. Find the “location ~ \.php$” in your nginx server block.


The nginx configuration in the picture shows that the PHP files are processed by fastcgi running on port 9000.
Let’s check what is running on the port:

netstat -pltn | grep 9000

If you get no results after issuing the command then the process has died. Thus, you see a 502 bad gateway error.
In the latest CentOS and Ubuntu, you can raise this command to see where the process should be running from:

systemctl list-unit-files | grep fpm

Issue this command to run the service:
systemctl start php7.0-fpm

Go to the browser and check the website now. If you can access the website without any intrusions then the error is gone. If the problem persists then move on to the next step.

Clear Cache

You are here because the first step did not work for you. To further troubleshoot your server try clearing the cache. This step is important because most web servers rely on caches so you have to make the browser load the latest version from the website. To do this simply press control + F5 on the keyboard if you are using Windows or Linux. For Safari browser press shift + reload button in the toolbar and CMD + shift + R for Chrome, Mac or Firefox. 

Try accessing your website again and check if the error is gone.

Disable CDN

Another quick and simple way of fixing 502 bad gateway errors is by disabling CDN for some time. Note that you should only do this step if you are using Cloudflare or another cloud service.

Check scripts

We have established that 502 bad gateway errors are mostly caused due to a problem with the webserver. Therefore, sometimes the communication error is also caused due to high memory usage by the server. For instance, the killing process can deny the request because of low memory space which causes the website to be down. To solve this problem check your PHP script to see if it is consuming high memory.

Check Themes and Plugins 

Plugins are small software components that add specific features to different programs or websites. WordPress is filled with plugins and themes which make it very interesting to use. However, sometimes they can cause errors in WordPress like the 502 bad gateway error. This is why you should also check if a plugin is causing the error. A simple way of doing so is by disabling all the plugins at the same time by renaming the directory. For this, you need to connect your server using an FTP client or SSH.

Now start enabling the plugins one by one until the error is reproduced. In this way you can identify the plugin which was causing the error and replace it to resolve the issue permanently.

To enable plugins to go to your wp-content directory, we can see that there is no plugins directory because we renamed it already. Let’s create a plugins directory and move a plugin over. This will automatically enable the plugin.


Solving WordPress errors is not as hard as you might think. However, sometimes it is good to ask for professional help if things get too complicated. This is why we recommend that you first troubleshoot the 502 error using the steps mentioned in this article but if the issue remains please contact professional web service. With that being said we are confident that the solutions mentioned here will be enough for you to fix the 502 bad gateway error on your own. Good luck! 

Leave a Reply

Your email address will not be published. Required fields are marked *