August 12, 2020
August 12, 2020
Each time you open a site, the browser sends out requests to other web servers. The servers then handle these requests and send back an HTTP status code along with the requested resources. Generally, the HTTP status codes are only displayed when a problem has occurred to inform users that something went wrong.
This tutorial focuses on the causes and fixes of the 502 bad gateway error on WordPress websites.
Find everything you need for WordPress Hosting with Hostinger today!
While the 502 bad gateway error usually relates to server-side problems, it can also be caused by misconfigurations or issues from the client-side. Hence, we’ll overview the common troubleshooting steps with both causes in mind. While some solutions are focused on WordPress, most of them can be applied to any website. So, let’s see the steps to fix the 502 bad gateway error:
The first solution is a fairly simple one. Wait around for a minute or two and refresh the page you’re on. In a lot of cases, the error is temporary and a simple page refresh will do the trick. For a shortcut, Window users press F5 or CTRL + F5 and Mac users press command + R. Meanwhile, you may also try checking to see if the website is down using an online tool.
If the error persists, there is a chance that a certain cached element is causing it. Thus clearing the browser cache is a good approach when troubleshooting the 502 bad gateway error.
Checking the connection using a different browser or incognito mode is also a great idea. It will let you rule out the option that the 502 error appeared due to a browser-related problem.
The 502 bad gateway error can also pop up due to DNS issues, such as incorrectly cached IP address values. In such cases, flushing DNS is another thing that you can try. Here’s a tutorial on how to flush DNS on Windows, Mac, and Linux.
You may also try temporarily switching your default DNS server to Google Public DNS.
If you have recently migrated your WordPress site to a new host, remember that it can take up to 24 hours to properly propagate.
If none of the above solutions fixed the 502 bad gateway error, test the connection on another computer or a mobile device, preferably connected to a different network. This is the final step that will rule out whether the error is related to your machine or if the problem lies elsewhere.
If the 502 bad gateway error appeared after a certain change or update, it’s possible that the fault lies within the website itself. The best approach is to check your error log.
In WordPress, you can enable error logging by adding the following lines in wp-config.php:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
All the generated entries will appear in wp-contents/debug.log file.
It’s also important to check your plugins, themes, and extensions. Issues with caching plugins can often lead to a 502 bad gateway error popping up.
If you are still able to access your WordPress dashboard, go to Plugins, and simply click Deactivate from the Bulk Actions menu.
Then, activate each plugin one by one, while refreshing your WordPress site after each one. Once the 502 error pops up again, you have found the problem plugin.
Another simple way to check if plugins are at fault is by disabling all of them for a short moment. To do it, navigate to the wp-content directory and rename the plugins directory.
If you use Hostinger, access your hpanel and click on Files. From there, go to File Manager -> public_html -> wp-content.
If the website starts working after all plugins are disabled, you may rename the folder back to plugins. Then try disabling the plugins one by one to determine which one caused the error in the first place.
If the website still doesn’t work, follow the same steps with your WordPress themes.
Another cause of the 502 bad gateway error can be CDN (content delivery network) or DDoS (distributed denial-of-service) mitigation services. One notable example would be CloudFlare, where the 502 bad gateway can occur in two different variations depending on the issue. This screen indicates that the issue in on CloudFlare’s side, and to fix it you’ll need to reach out to their customer support team. Easily check CloudFlare System Status before doing so. Alternatively, you may choose to disable CloudFlare, though keep in mind that DNS propagation may take a couple of hours.
However, if you see this version of the error, it means that the issue lies with your current hosting provider.
If the 502 error is still showing up it is possible that other people are having the same problem. There are many tools on the web to examine if a site is down, but a good one to use is Down for Everyone or Just Me or IsItDown. Simply input your URL and check the status of your website.
If you are importing WordPress files and a lot of them, you could see an error 502 bad gateway as a result of that. This will happen when a single PHP process runs longer than it should. The max_execution_time (max_input_time) is in your PHP configurations on your web server.
Talk to your web host if you want to know what your values are set at and if you can increase them.
If none of the above solutions fixed the 502 bad gateway error, then it’s best to contact the customer support team. While describing the issue, try to include what troubleshooting steps that you took. Provide as much information as possible and you’ll surely be assisted.
HTTP status codes that start with the digit “5” relate to errors that occur when there’s a miscommunication between several servers. Though the exact reason for their appearance varies, in most cases the cause lies within the server-side.
Getting a 502 bad gateway error means that the origin server sent out an invalid response to another server that acted as a gateway or proxy. Since all requests on the web are forwarded through multiple gateways, it can be quite tricky to locate the exact point or process which caused the issue. However, there are general troubleshooting steps that you can follow to fix it.
Since there are a number of browsers, operating systems, and web servers, the 502 bad gateway error may also appear with various names. Here are some alternatives that you can encounter:
Keep in mind that some websites have custom 502 error pages and will look different.
In this tutorial, we’ve learned what 502 bad gateway error is and how to approach it with basic troubleshooting steps.
In case you have any extra tips, tricks, or solutions, feel free to share them with us in the comments below.