In this article, we will explain one of the WordPress errors known as 502 error code, and will tell you how to fix 502 bad gateway error in WordPress.
An Introduction to HTTP-Status-Code 502 + 9 ways to fix 502 bad gateway error in WordPress
When it comes to a website (especially a WordPress one), there are always a lot of errors or different kinds of failure that can be frustrating. You might probably encounter one of the WordPress common errors such as HTTP 404,HTTP 429 too many request, or even this error: “upload filed to write file to disk”. Some of them can be fixed as easy as ABC, while other errors may be frightening (e.g. white screen of death). In this article, we will speak about one of these errors known as 502 error code. We will tell you how to fix 502 bad gateway error in WordPress. But, before that, let’s start with its definition.
What is a 502 Bad Gateway Error?
To fix 502 bad gateway error in WordPress, first you should know what the meaning of this code is, and when it happens. HTTP code 502 is a common error happened when you are trying to visit a web page while the server gets an invalid response from another web server. In fact, this error is a server side error and rarely caused by Wi-Fi connections or computer of users. In fact, 502 bad gateway meaning is the error that is related to the server you are going to visit. This error also known as 502 error code, http 502 error, error reference number: 502, HTTP status code 502, and WordPress 502 error. Below is a list of different variation you might see on the web:
- “502 bad gateway”
- “Error 502”
- “HTTP 502”
- Temporary Error (502)
- “502 Proxy Error”
- That’s an Error
- “HTTP Error 502 – Bad Gateway”
- Bad Gateway: The Proxy server received an invalid response from an upstream server.
- 502 bad gateway Cloudflare
- “502 Service Temporary Overloaded”
- A blank white screen
- “502 Server Error: The server encountered a temporary error and could not complete your request”
Another variation can be: “502 – Web server received an invalid response while acting as a gateway or proxy server”. In this case, there is a problem with the page you are looking for and can’t be displayed. In this error and HTTP status code 503, you can’t preciously tell what happened and what’s going wrong. But there are common issues that some of them will explain in the next paragraph.
Why 502 Error Happens?
Every time you visit a website, the browser will send a request to your web server. The web server receives all requests and start processing them. Then, these requests will send back to the browsers along with HTTP status codes and a HTTP header. If the process goes wrong or any problem occurs, you can see these errors. In fact, these codes are the language of your server to notify you that something goes wrong.
As you probably know, there are different kinds of HTTP status codes (e.g. 500, 501, 502, 503, 520, etc.) that are different meaning, and 502 bad gateway meaning indicates that when a server acts as a gateway or a proxy, happening of this error will be probable. Below are three main issues that cause 502 bad gateway responses. These includes:
- Origin Server Down: in this situation, the server is not reachable. This may occur when server is down or there is no connectivity to the server.
- Firewall Block Request: when firewall blocks the communication between the main server and edge server, occurring this error will be probable. This can also occur by security plugins of your content management system.
- Domain Name Not Resolvable: sometimes, the domain name is not resolving to the correct IP and it is important to note that DNS changes to a new server takes some times to completely propagate and active. So it may cause the 502 error in WordPress sites.
How 502 Errors Can Negatively Affect Your SEO?
You should hurry to fix 502 bad gateway error in WordPress, because it negatively effects on the SEO of your site. If your site remain down for only 10 minutes, the crawlers will simply delivered the page from the cache. You may also loose the chance of re-crawling.
If your site is down for an extended period of time (i.e. 6+ hours), then Google might see this error as a site level issue that should be addressed. This problem can highly impact on the ranking of your WordPress site. So, try to fix this problem as soon as possible.
9 Ways to Fix the 502 Bad Gateway Error?
Although facing an error in a WordPress site is horrifying, but chance is here you can simply fix the 502 bad gateway error, most of the time. In the following, we will provide you a few solution for fixing this error:
1. Try to Reload the Selected Page
Sometimes, this error can be simply fixed. So, wait for a minute or so. Then, try to reload the page (F5 or Ctrl + F5). If the page loads with no error, this might have been a temporary connection problem. It means that your server or your host simply overloaded and the site will be fixed. But if the page still showing you an error, clear your browser cache and then try reloading t once again. If the page doesn’t work, move on to finding the real cause of the error.
2. Look for Server Connectivity Issues
Most websites run on third-party hosting providers or multiple servers. If your server is down and your website shows your visitors this error, to fix 502 bad gateway error in WordPress you’d better to wait for your server to finish maintenance or fixing the problem causing the error.
3. Check the Situations with Your Host
Sometimes, a script, a query, or a request will take too long so that it will be canceled or killed by the server. In fact, all of these processes will terminate after a certain period of time. Therefore, error 502 bad gateway fix process can be done via contacting your WordPress hosting provider. One problem connected to your host is that the platform runs in a non-isolated container. It means that the software that runs each site is a shared one and is not completely private. This greatly increased the chance of seeing 502 bad gate way error.
Another reason for seeing HTTP status code 502 is because of the fact that the server is not reachable. It means that there is no connectivity or the server is down. So, you’d better to contact to your host by calling them or sending a ticket. You can also run a ping test to see if messages are reaching to your IP or not.
4. Check Your Plugins and Themes
A lot of time, a misused plugins or themes may cause an error. Sometimes, scripts and queries will canceled because of bad code in WordPress themes or plugins. We have also seen a lot of misconfigured caching plugins which generate a 502 error.
In these cases, the first action can be deactivating them. Then, start to active them one by one to fix 502 bad gateway error in WordPress. Always, make sure to update your website plugins to the latest version, and check to ensure you are running a supported version of PHP.
5. Temporarily Disable CDN or Firewall (Faulty Firewall Configurations)
Sometimes, the real cause of 502 error code is related to your website’s firewall or Content Delivery Networks (CDNs). The simplest way in this case is to temporarily disable the CDNs if you are using a CDN third-party. You may also are using some plugins for CDNs, so to fix 502 bad gateway error in WordPress, simply deactivate your related plugins.
This error can also happen with providers providing DDoS (Distributed-Denial-of-Attacks) protection, or fully proxy services like Cloudflare that have extra firewalls. This sometimes will happen in Cloudflare free plan. Unfortunately there is no quick solution in this case, since Cloudflare is a fully proxy service. In fact, you’d better to know that there are two different 502 bad gateway error variations with Cloudflare as seen below:
- When the problem is connected to your host.
- When the problem is a problem on Cloudflare’s end.
Sometimes, a fully firewall configuration will cause the 502 bad gateway error. In this process, a request from a content delivery network will deem as an attack on your server so that the server will reject it. As a result, a 502 bad gateway error occur. To fix the error in this situation, check your firewall configuration to fix the problem.
6. Check Logs
Error log will often help you to fix 502 bad gateway error in WordPress. Some hosting providers provide you with logs so you can easily see the errors in the log viewer, and quickly fix the issue. This method will help you especially when a plugins is caused the error 502 in WordPress. If your hosting provider doesn’t have a logging tool, you can easily add the following code to your wp-config-php file.
define (“WP_DEBUG’, true);
define (“WP_DEBUG_LOG’, true);
define (“WP_DEBUG_DISPLAY’, false);
You can also check log files in Apache and NGINX, which commonly are located in the following path:
- Apache: /var/log/apache2/error.log
- NGINX: /var/log/nginx/error.log
7. DNS Issue
When your WordPress site have just migrate to a new host, DNS issue may cause a 502 error. In this situation, you’d better to wait for thing to fully propagate from old host to new one. This completely depends upon the TTL value of your DNS records. You can also try flush DNS. Flushing your local DNS cache is something like clearing your browser cache.
For Windows platform, open up command prompt and type the following:
Ipconfig / flushdns
If it worked, you can see a “Successfully flushed the DNS resolver Cache” message. For macOS users, enter the following terminal:
Remember that macOS has no success message for this terminal. You can temporarily change your DNS server. For example, you can change it to a public DNS server such as Google. In some cases it really works.
8. Restart PHP
Another solution to fix 502 bad gateway error in WordPress is restarting PHP. Some hosting providers provide a tool to make this process easy. But if your host doesn’t provide any tool, you can always ask your hosting support team to restart PHP.
9. PHP Timeout Issue
If you are doing big WordPress imports, PHP Timeout will occur. When this error happens a 502 error will display. In this situation, a single PHP process runs for longer than the max_execution_time or max_input_time. By changing these value, you can fix 502 bad gateway error in WordPress.
When your WordPress hosting gets an invalid response for the requested page, a 502 error will occur. In this article, we’d discussed 502 bad gateway error in WordPress as well as three main issues that cause this kind of HTTP Status Codes. This error is quite annoying because it can be created with a lot of different things. Therefore, the process of troubleshooting and finding the real cause takes some times. But, with suggested solutions we’ve discussed, you can save your time and fix the 502 bad gateway error in WordPress sites.
1. What Does Error 502 Means?
The HTTP Error 502 means a server error, and indicates that the server while acting as a proxy or a gateway. The troubleshooting of this error is a bit annoying because the various things can cause it.
2. How Do I Fix Error 502?
To fix the error 502 bad gateway, you can try the following solutions:
- Refresh the page.
- Restart your computer and networking equipment.
- Start a new browser session or load the site with different browser.
- Clear the cache and cookies
- Contact your Internet Hosting Provider.
- Disable your firewall
- Check your WordPress plugins and themes.
3. Is 502 Bad Gateway Error Bad?
Every error can be annoying and makes your users have an awful experience. Since this error is a general indicator that tell you there is something wrong in your site, it can be bad. Therefore, you can try to fix it as soon as possible.
4. Does 502 Bad Gateway Mean Blocked?
502 Bad Gateway error doesn’t really mean a block. This error indicates that the edge server was not able to get a valid response from upstream server. Therefore, this error has happened.
5. What Causes Bad Gateway?
It may happen by network errors such as DNS issues, ISP related issues, and routing problems, or the problems related to the server software timeouts, or even can be created by slow queries.