There are numerous 502 Bad Gateway Errors with WordPress that might be really annoying and baffling. The fearful white death screen and the intimidating challenge of establishing a database connection are two examples. The 502 bad gateway error, on the other hand, is a lot more common. Why? It is not only commonly on the internet but also infamous services such as Gmail, Twitter, and Cloudflare. This happens on WordPress websites. But of course, it affects your WordPress site, we’re interested just in it. Learn more about what causes this mistake and how to easily fix it in the sections below.
Table of Contents
What is a 502 Bad Gateway Error?
The 502 Bad Gateway error indicates that an incoming server sent an incorrect response to the server.
Your browser sends a request to a web server every time you visit a website. The request is received from the web server and processed and returned with an HTTP header and an HTTP status code, the resources requested. An HTTP status code is hardly noticed if anything goes wrong. It’s essentially the way the server tells you something has gone wrong and gives you the code to resolve the problem.
500 status error codes come in a variety of forms (500, 501, 502, 503, 504, 508, 520, and so on), each with its own set of meanings. These indicate that the request was accepted but not processed by the server.
502 Bad Gateway Error Variations
A 502 wrong gateway error might appear in a variety of ways depending on the browser, web server, and operating system used. But they all mean the same thing. Here are just a few of the many different variants you could come across on the internet:
- “502 Bad Gateway”
- “Error 502”
- “HTTP Error 502 – Bad Gateway”
- “502 Service Temporarily Overloaded”
- “502 Proxy Error”
- A blank white screen
- “502 Server Error: The server encountered a temporary error and could not complete your request”
- “HTTP 502”
- Temporary Error (502)
- That’s an error
- 502 bad gateway Cloudflare
- Bad Gateway: The proxy server received an invalid response from an upstream server
A “502 server error” is another type you can encounter.
And here’s another take on the theme. “502 – While functioning as a gateway or proxy server, the webserver got an incorrect response. The page you are looking for is a problem, so it cannot be shown. When the Web server contacted the upstream content server (while functioning as a gateway or proxy), the content server returned an incorrect response.”
For a 502 Bad Gateway error, other services, such as Twitter, may display a completely different message, such as “Twitter is over capacity.” This appears to be a little easier to use.
Here’s an example of how Google presents it. “502. That’s a mistake. Your request could not be completed because the server experienced a temporary issue. Please come back in 30 seconds and try again. We don’t know anything else.”
502 Errors Impact on SEO
A 502 error, unlike 503 failures, which are used for WordPress maintenance mode and encourage Google to come again later, can have a detrimental impact on SEO if not repaired straight away. If your site is only down for 10 minutes and is crawled frequently, the crawler will just fetch the page from the cache. Or Google might not have time to re-crawl it before it goes down again. You’re perfectly right in this situation.
If the site stays down for a long time, say 6 hours or more, Google may interpret the 502 error as a site-level problem that has to be resolved. This could have an effect on your search engine rankings. If 502 errors are concerned, you should decide first of all why they occur. There may be some useful ideas provided below.
How to Fix the 502 Bad Gateway Error
A 502 bad gateway error normally indicates a network/server problem, but it can also signal a problem on the client side. As a result, we’ll do a little bit of everything. To get back up and running, look into these typical reasons and solutions for the 502 bad gateway issue.
1. Try Reloading the Page
When you get a 502 bad gateway problem, one of the first things you should do is wait a minute or so and then reload the page (F5 or Ctrl + F5). The host or server can be overloaded and the website will emerge again. It’s possible. You could try a different browser while you wait to see if that’s the issue.
Copy the URL and paste it as an alternative into downforeveryoneorjustme.com This website tells you whether the website is down or if you are having trouble.
2. Your Browser Cache
The option “Clear Browser Cache” in Google Chrome is the quickest way to clear cache data. This function can be accessed using the following shortcut:
- Hold down the [Ctrl], [Shift], and [Del] keys. Make sure you push all of the keys at the same time.
- “Clear Browser Cache” appears in a new window.
- You can choose which time period you want to remove the cache data for in the upper dropdown menu. Choose from “last hour,” “last day,” “last week,” “last four weeks,” or “all.“
- Select “all” if you wish to erase all cached data.
- Select “Images and Files in Cache” from the drop-down menu.
- Click the “Delete Browser Data” button to submit your option.
- Reload the page.
More Read:- How to get email addresses from fans and followers in social media
3. DNS Issue
A DNS issue, for example, a domain that does not solve the right IP or a DNS server that does not answer, can also lead to a 502 gateway error. It’s critical to wait for things to properly propagate after migrating your WordPress site to a new server, which might take up to 24 hours in some situations. The TTL value of your DNS records determines this.
You might try cleaning up your local DNS cache as well. This means that the cache in your browser gets deleted.
Simply open Command Prompt in Windows and type the following.:
ipconfig /flushdns
If it worked, you should receive a message that says “Successfully flushed the DNS resolver Cache.”
You can use the terminal to do the following for macOS users:
dscacheutil -flushcache
Finally, your DNS servers can be changed temporarily. Your ISP automatically supplies DNS servers by default. You can, however, try to switch on a public DNS server like Google briefly. In reality, some people choose to use Google’s public DNS for long periods of time. Propagation is normally faster if you have a premium DNS.
4. Check With Your Host
A server fault with the web host is the most prevalent cause of a 502 bad gateway error. If it takes too much time to execute a request, script, or request, the server cancels or kills it. Many hosts utilize what is known as a “kill script,” in particular shared hosts. This basically means that a request is canceled after a certain period so that it does not download or influence other users. Thousands of tweets per day alerting their hosting firm of the situation can be found by searching Twitter for “bad gateway.”
Our platform runs in an isolated software container with all the software tools needed to run the site, thus you may think that you would move to a host like Kinsta (Linux, NGINX, PHP, MySQL). This implies that the software that operates each site is completely private and not shared with other sites, including your own. The likelihood of encountering a 502 bad gateway error is considerably reduced as a result of this. Unlike some shared hosts, we don’t use aggressive kill scripts. It doesn’t have an impact on the others even if one of your sites goes down.
Another reason you can notice a 502 gateway error with your host is if the server isn’t reachable, either because it’s down or because there’s no connectivity. You should in this circumstance check your WordPress host’s status page or create a help ticket.
5. Temporarily Disable CDN or Firewall
It could potentially be a problem with your firewall or content delivery network (CDN). You may simply resolve this by temporarily disabling your CDN if you are using a third-party CDN. The free CDN enabler plugin, for example, is one of our favorites. If you use it, disabling and testing your site is all you have to do now. WP-admin isn’t working for you? Rename the plugin’s folder to CDN-enabler old after logging in to your site via SFTP. The CDN connection will be momentarily disabled as a result of this. The same applies to WP Rocket or any CDN plug-in installed by you.
Because they have additional firewalls, this can also happen with suppliers providing DDoS protection and mitigation or providing full proxy services such as Cloudflare. On the Cloudflare free plan, we’ve noticed that this happens every now and then. Sadly, as Cloudflare is a full proxy service, there is no easy method to disable it.
However, before you start blaming Cloudflare, you should be aware that there are two forms of 502 bad gateway problems with Cloudflare, as shown below:
502 Bad Gateway at Cloudflare
If you view the following screen, there is an issue on Cloudflare’s end, and you should contact them for assistance. You can also check the Cloudflare status page to verify if they are not.
GoDaddy Firewall
Below is another HTTP 502 and GoDaddy Firewall Error sample. Another example. A timeout (hosting provider), not the firewall, is responsible for the problem.
6. Check Your Plugins and Themes
Bad code on your WordPress site, potentially from a 3rd party plugin or theme, is frequently the cause of scripts and queries being terminated by the server. A lot of 502 errors caused by misconfigured caching plugins have also come across. Deactivating all of your plugins is one approach to troubleshooting this. Remember that merely deactivating a plugin will not result in any data loss.
If you still have access to your admin, go to “Plugins” and pick “Deactivate” from the bulk actions menu. All of your plugins will be disabled as a result of this. If this resolves the problem, you’ll need to identify the source of the problem. Start to activate them one by one, then load the website one by one. You’ve found the problematic plugin when you see the 502 gateway error return. You may then contact the creator of the plugin or create a support ticket for help.
You can FTP into your server and change your plugins folder to something like plugins old if you can’t access your admin. Then check your website for a double-check. If it works, each plugin needs to be individually tested. Rename your plugin folder to “plugins” and then rename each plugin folder inside it until you discover it.
Make sure your plugins, themes, and WordPress core are all up to date at all times. Also, make sure you’re using a PHP version that’s supported. If you need help, you can always contact your host. At Kinsta, we use New Relic and other diagnostic tools to help clients figure out which plugin, query, or script is causing the problem. You can also use a New Relic key that you created yourself.
You may need to hire a WordPress developer to repair the problem if it turns out to be an efficient query or incorrect code in a plugin.
7. Check Logs
You should also use the information in your error logs. If you’re a Kinsta customer, you can quickly detect issues on the MyKinsta dashboard’s log viewer. This can help you narrow down the problem quickly, especially if it’s caused by a plugin on your site.
If your server does not provide a logging tool, you can enable logging by adding the following code to your wp-config.php file:
define( ‘WP_DEBUG’, true );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
If you need additional information on how to enable WordPress debugging mode, here is a comprehensive guide.
The logs are usually kept in the /wp-content folder. Others, like ourselves at Kinsta, may have a dedicated “logs” folder.
You can also look at the log files for Apache and NGINX, which are usually found here:
- Apache: /var/log/apache2/error.log
- NGINX: /var/log/nginx/error.log
If you’re a Kinsta customer, you can use our analytics tool to get a breakdown of the total number of 502 errors, as well as how frequently and when they occur. This can assist you in figuring out if the problem is still there or if it has already been resolved.
8. Restart PHP
Finally, restarting PHP is an option. If you’re a Kinsta customer, you can easily restart PHP from the MyKinsta dashboard’s tools menu. If your server does not offer this, you may always submit a support ticket and request that PHP be restarted.
9. PHP Timeout Issue
PHP timeouts happen when a single PHP process runs longer than the max execution time or max input time settings in your server’s PHP configuration. If you’re running large WordPress imports, this is a typical occurrence. A 502 server error is frequently presented when this happens. If a PHP timeout occurs, these numbers may need to be increased.
Check with your existing WordPress host to see what values are currently set on your server and whether they may be increased. These parameters are set to 300 seconds (5 minutes) by default on the Kinsta platform. Your current hosting plan determines the maximum PHP timeout settings accessible on our platform.
Summary
As you can see, there are several options for troubleshooting and resolving a 502 gateway problem on your WordPress site. Typically, this is not a client-side issue, but rather a host-side issue. Third-party plugins and themes with faulty code or queries that aren’t optimized should also be avoided. Is there anything we left out? Maybe you know of another approach to troubleshooting 502 gateway problems. If so, please let us know in the comments section below.