WordPress is simple, but troubleshooting issues that might happen at any time is equally aggravating. To effectively treat a sickness, just as you would prescribe the appropriate medication, you must be fully informed about the illness. Prior to troubleshooting, it is necessary to understand the mistake and its causes.
It’s like unraveling a puzzle when you have a 502 Bad Gateway Error on your website. You’re not sure what specifically went wrong or why you think there’s a problem that needs to be fixed. I’ll explain the 502 Bad Gateway Error and how to resolve it in your WordPress in this blog.
What Is the 502 Bad Gateway Error?
You need be aware of how a browser loads data from the server in order to comprehend the 502 Bad Gateway Error. The server sends a request to gather the necessary data so that the content may be shown in the browser when a user visits a website.
The requested content is sent to the server in the event that it accurately processes the requests. The 502 Bad Gateway Error screen appears otherwise.
WordPress websites operate on several servers, each dedicated to a particular job. As an illustration:
- Database server for WordPress databases,
- Application server to run PHP and other app-related content,
- The reversed proxy server responsible for Nginx, Apache, Varnish,
- Web server to serve website files.
The combination of several servers may make it more difficult for the browser to process requests. The reversed proxy server retrieves data from origin servers, such as database servers, application servers, and web servers, upon receiving the request.
The inverted proxy server replies to the browser with a 502 Bad Gateway Error if any of these servers give an incorrect answer.
Although we frequently encounter 502 Bad Gateway Errors on many websites, they always indicate that the server was unable to process the request. Let’s examine a few of the instances where this problem occurs.
- “502 Bad Gateway”
- “HTTP Error 502 Bad Gateway”
- “502 Service Temporarily Overloaded”
- “Error 502”
- “502 Proxy Error”
- “HTTP 502”
- “502 Bad Gateway NGINX”
- “502 Server Error: The server encountered a temporary error and could not complete your request”
- “502. That’s an error. The server encountered a temporary error and could not complete your request. Please try again in 30 seconds. That’s all we know.”
Google displays a 502 Bad Gateway Error with the suggestion of trying again after some time.
Now that we have understood what is 502 Bad Gateway Error is and how different websites display it. Let us move ahead and explore what causes this error and how can we fix it in WordPress?
Why Does 502 Bad Gateway Error Occur in WordPress?
When the server returns the request with inaccurate information or fails to answer appropriately, we receive a 502 Bad Gateway Error. But if you want to properly debug this mistake, you also need to be aware of other options.
- Your server is busy with other tasks or hit by traffic spikes
- Origin servers are unresponsive or inaccessible
- Errors in the database
- Problem with the reverse proxy server
- Corrupt PHP scripts in WordPress files
- WordPress CDN is acting up
- DNS issues
The 502 Bad Gateway Error in WordPress might arise from any of the aforementioned scenarios. Troubleshooting any issue, though, becomes more difficult if you are unaware of the factors that led to it.
How Does 502 Bad Gateway Affect the SEO
The traffic to your website will suffer if the 502 Bad Gateway issue frequently causes it to go down. If a visitor to your website encounters this error, he may decide not to return. Similar to that, its unavailability will affect how your site is crawled and indexed. You will therefore lose both traffic and your organic ranking.
Fix 502 Bad Gateway Error in WordPress
1. Check Hosting Server
Making sure your web server is responsive should be your top priority. It’s not always the case that your WordPress website is experiencing bad things. Doing an internet search is the simplest method to find out if the problem is with your server. Go to site24x7 and type the URL of your website.
Your server will display the ping every time it answers.
Any query or task that takes longer than usual may occasionally be canceled by the server and returned with a 502 Bad Gateway Error. In shared hosting, it is typical for the provider to terminate the script in order to prevent any detrimental effects on other websites hosted on the same server.
You are unlikely to encounter this problem if you are utilizing Cloudways. This is because we employ a strong stack that can handle server load, and you are the only owner of your server and in charge of the websites hosted on it.
But if you continue to have problems, Cloudways’ round-the-clock live chat service can assist you in getting through this situation.
2. Reload Web Page
Reloading the webpage can occasionally save hours upon hours of debugging. It’s conceivable that you have an overloaded server for a while, but it should come back online in about a minute when you check again.
Verify whether the website is down for you and everyone else as well. To do this, try the URL on Down for Everyone or Just Me.
If the website is up for everyone else, then the problem is at your end. Try switching the web browser.
3. Clear Browser Cache
To save the browser from having to download the same static information over and over again when a user returns, the browser caches or stores site data. Although it is a useful method of using resources, there are several disadvantages.
Suppose you switched to an other browser and the website opened without any issues. You switch back to your preferred browser, knowing that your website loads properly, yet the problem still exists. This is because the web page is shown by your browser using a cached copy. To resolve that, use Ctrl+Shift+Del on Windows or Shift+Cmd+Del on Mac to clear the cache in your browser.
4. Check DNS Issues
An IP address and a domain name can be connected using the Domain Name System (DNS). An IP address that is incorrectly resolved by the domain may result in a 502 Bad Gateway Error. It frequently happens when a WordPress website needs to have its DNS name server changed in order to migrate to a new host.
The propagation of the DNS updates may take 24 to 36 hours. You may receive a WordPress 502 Bad Gateway Error if you attempt to access your website during this time.
5. Clear DNS Cache
The DNS cache can be cleared using the Windows Command Prompt. Use the ipconfig/flushdns command in Windows to empty the DNS cache. Use the command “dscacheutil -flushcache” in the terminal window on a Mac.
6. Disable CDN/Firewall
The servers of any firewalls or CDN services you use for your website might be malfunctioning.
A CDN speeds up website loading times for visitors from around the world by serving static information. A firewall, on the other hand, defends your website from DDoS and other internet threats. However, because a CDN or firewall adds an extra layer between the server and the browser, it may be one of the causes of the 502 Bad Gateway Error in WordPress.
You can remove this from your list of potential causes by simply trying to visit your website after disabling your firewall or CDN. If the webpage loads properly, you’ve found the offender. To repair it, all you have to do is get in touch with your CDN/firewall service provider.
7. Audit Themes/Plugins
Without installing themes and plugins, it is almost difficult to have a completely functional WordPress website. However, they might also end up being one of the causes of the 502 Bad Gateway Error. The greatest WordPress plugins reduce the issue, but they also increase the risk of a 502 error. They can slow down your web server or take too long to execute requests if they are poorly written. Even if you use the greatest WordPress themes for your website, the issue may still occur.
Deactivate each and every plugin via FTP first. To make the plugins folder unavailable to your site, simply access the public_html folder, which is your site’s root directory where WordPress files are located. From there, go to wp-content → plugins and rename the folder.
Once your website has loaded properly, activate each plugin one at a time until you identify the one that is generating the 502 Bad Gateway Error.
If you are unable to identify any malfunctioning plugins, search for a faulty theme. To deactivate an activated theme, go to your wp-content folder, browse to themes, and rename the theme. Removing your theme may not be appropriate because uploading it again may result in the loss of customized customization.
If you receive a white screen instead of an error when you refresh your website in the following step, your theme was the source of the problem. Open the WordPress admin panel and turn on the default theme.
8. Check Error Logs
WordPress logs are useful when it comes to troubleshooting errors. You can enable the error logs by adding the following code inside the wp-config.php file.
You may find the logs under the wp-content folder. For accurate and thorough analysis, Cloudways users can benefit from the integrated monitoring tool New Relic.
9. Set PHP Timeout
PHP displays an error when it reaches the maximum amount of time allowed by the server configuration to run a script. Occasionally, it may result in a 502 Bad Gateway Error on WordPress. Just raise the maximum execution time value to prevent this. By default, it is set to 300 seconds, or five minutes.
10. Check Custom Scripts
We develop unique WordPress themes and features. Our web server occasionally has trouble processing these unique features. Additionally, invoking other APIs, like Google reCAPTCHA, might cause server stress and result in the 502 Bad Gateway Error. These APIs generate lengthy tokens.
Conclusion
I hope the next time you see a 502 Bad Gateway Error, it won’t look quite as scary after reading this article. If you can identify the source and utilize the methods in this article to resolve it, troubleshooting is simple.
Reloading and cleaning the browser cache will still resolve the WordPress 502 Bad Gateway Error, but because not every day is sunny, it’s best to be ready for the unexpected.If you have releant error like Http Error 501 you can just solve via this link.