The 502 bad gateway error is one of the many status codes a WordPress site may experience from time to time.
Though the error message is also popular with other platforms like Twitter or Cloudflare, it is one of the more common errors for WordPress. The 502 bad gateway error can have an impact on your site’s SEO.
There are many reasons why you’re seeing the 502 error message. It can be caused by issues with your DNS server settings or PHP timeout settings. It can be frustrating trying to troubleshoot the exact problem causing the error message.
In this article, we’ll explain what is a 502 bad gateway error, what could be causing the error, and the different ways to fix it.
Table Of Contents
- What is a 502 Bad Gateway Error?
- 502 Bad Gateway Error Examples
- 502 Errors Impact on SEO
- How to Fix the 502 Bad Gateway Error: 5 Ways
- Cloudflare 502 Bad Gateway Error
- Check Your Plugins and Themes (Troubleshooting Mode)
- Take A Look At Your Error Logs
- Restart PHP and Rebuild Web Application in RunCloud
- PHP Timeout Issue
What is a 502 Bad Gateway Error?
Your browser sends a request to the webserver every time you visit a website. The web server receives the request and processes it. It then sends the requested resources back to the browser.
Simply put, the 502 bad gateway error occurs when the server has received an invalid response from the inbound server. The error message tells you the request was accepted, but an issue occurred while trying to fulfill the request.
502 Bad Gateway Error Examples
The 502 bad gateway error message can appear in a number of ways. You may see a blank white screen or some of these variations in the error message.
- Error 502
- 502 Proxy Error
- 502 Service Temporarily Overloaded
- 502 Bad Gateway
- HTTP Error 502 – Bad Gateway
- HTTP 502
- 502 server error
Your browser and certain websites are able to customize how the error message is shown. How the message is displayed to you depends on your browser, web server, and operating system.
502 Errors Impact on SEO
A 502 error can have a negative impact on your SEO if it’s not fixed soon. If your website is experiencing this issue for only a few minutes and it’s consistently being crawled, the crawler may just get the page delivered from the cache folder. There may be a chance Google will not be able to re-crawl before the site is working again. If this is what you’re experiencing, it won’t impact your SEO rankings.
However, if your website has not been fixed for more than a few hours, Google might consider the 502 error as a site-level issue that needs to be addressed immediately. This can affect your SEO rankings.
How to Fix the 502 Bad Gateway Error: 5 Ways
The 502 bad gateway error is usually an issue with the network or server. While it can also be an issue on the client side, it’s not very common. Here are some ways you can use to try fixing the 502 bad gateway error.
1. Try Reloading the Page
One of the simplest first steps you should try is to wait a while before reloading the website. There is a possibility the host or server is overloaded, or there was a temporary connection problem.
To reload your browser, click the refresh button or the F5 key to prompt the website to send another request. If it was a temporary interruption, the page will start loading after the refresh. Alternatively, you can try some of these other suggestions.
- Turn off your VPN, then refresh the website again
- Try a different browser
- Restart your browser
If the 502 bad gateway error was caused by a temporary connection issue, these steps will help you fix it, and load your website. Refreshing a page sends the server a new request asking for the latest version of the website you’re viewing. It’s possible you’ve encountered a temporary connection issue, especially if the server was maintenance.
2. Restart Your Network Devices
Any temporary disruption in your network connection can cause the gateway timeout error. A simple way to troubleshoot this is to restart all your network devices, including your modem and router.
All you have to do is unplug both your modem and router. Then wait at least 30 seconds before plugging it back in. After that, you’ll have to wait for at least 60 seconds before starting everything back up to see if the issue is still there.
3. Clearing Your Browser Cache
The second easiest step is to clear your browser cache. Your browser saves certain information from the website you’re visiting. This is helpful as it speeds up the time it takes to look for that information and removes the need to constantly download the same resources.
But sometimes, the saved cache can be corrupted, which will cause the 502 bad gateway error. There are different ways to clear your cache, depending on the browser you’re using.
For Google Chrome:
- Head to the three-dot menu at the upper-right corner of Chrome.
- From there, click on More tools at the bottom area of the pop-up menu.
- Then select Clear browsing tools.
- This will then open a dialog box to delete all your browsing and download history.
- Check the box with Cached images and files.
- Select All time.
- Click Clear data.
For Microsoft Edge:
- Head to the three-dot Menu at the upper-right corner of Microsoft Edge.
- Select Settings from the list.
- Click on Privacy, search and services.
- Select Clear Browsing Data.
- Select what you would like to clear and then click Clear now.
For Internet Explorer:
- Select the gear icon on the upper left of Internet Explorer.
- From the menu, select Internet Options.
- Alternatively, you can click the Delete button to delete all your history, cookies, and cached data.
You’ll want to restart your browser once you’ve cleared the cache as well, just to make sure your browser is in order. If you’re using a browser like Brave, Opera, or something else, you can easily Google the steps to delete your browser cache. You should find the steps fairly easily after that.
4. DNS Issue
The 502 gateway error can also happen when the domain is not providing the correct IP address or if the DNS server is not responding. DNS servers are assigned by your ISP by default, but you can change this yourself to see if it will fix the issue. You can try third-party DNS servers, which might solve the problem.
Some of the best free public DNS servers can be found below:
- Google DNS – 188.8.131.52
- OpenDNS – 184.108.40.206
- Cloudflare – 220.127.116.11
There are two ways to change your DNS settings. The first is to change your router settings, and the second is to add the new DNS right into your device.
To change the DNS server on Windows:
- Open the Start menu and select the gear icon (Settings).
- Once you’re in settings, click Network and Internet in the Settings menu.
- From there, select Change adapter options.
- After that, right-click your chosen internet connection and select Properties.
- Click Internet Protocol Version 4, then click the Properties button.
- Next, select the item labeled Use the following DNS server addresses.
- Enter your two chosen addresses.
- Click OK to save your changes.
Changing DNS Server on macOS:
- Select Preferences from the Apple Menu.
- Launch the Network app.
- Select your internet connection then click the Advanced button.
- In the Advanced window, select the DNS tab.
- Use the plus sign on the right to add your chosen DNS addresses.
- Click OK to save your changes.
Changing the DNS server directly on your router will affect all your connected devices, including home security and smart appliances. To do this, we recommend doing a web search on “how to change DNS” followed by the make and model of your router. This will provide you with instructions that are specific to the router you’re using.
This might help solve the 502 bad gateway error message. When you change the assigned DNS server on your router or devices, you’re prompting your devices to use a different domain to search for the IP addresses. This might help you access sites your ISP has chosen to block for any reason, which can cause the 502 bad gateway error.
5. Check With Your Host
One of the main reasons for a 502 bad gateway error is an issue with the web host. A request may take too long, resulting in it being canceled by the server. Certain hosts implement a “kill script” feature that terminates a request after some time, so it doesn’t affect the main site or other users.
Here are a few steps you can take to see if there are issues with the server and if you should contact your host.
- Try accessing the website from other devices, for example, your mobile phone. If you are able to view the website on your mobile phone, but not your computer, it tells you the problem lies with the settings in your computer and not the server. However, if it does not work on all your devices, you should call your hosting provider for assistance.
- You can also do a Google search “is abc.com down” or check Twitter to see if other people are experiencing the same issue.
- Websites like Downdetector will also be able to tell you if the website is currently experiencing technical issues and if other people are having problems connecting to it.
- It’s recommended for you to check your WordPress host’s status page as well.
If you’re experiencing the 502 bad gateway on a regular basis, it’s a good idea to contact your host to find out if that is the reason or if the site is just under maintenance.
6. Temporarily Disable CDN or Firewall
The content delivery network (CDN) or firewall you’ve selected could also be causing the 502 bad gateway error. If the original server of the website cannot be reached, the CDN will automatically load the website from its cache folder. However, this feature isn’t enabled in some CDNs.
- Go to the WordPress admin dashboard.
- In the Settings tab, select the Popup plugin.
- Activate the ‘Disable CDN usage’ option.
- Make sure to save your changes.
If you’re using WP’s Engine CDN, these are the steps you need to take to temporarily disable CDN:
- Login to WP Engine’s User Portal.
- Select Sites.
- Click on the production environment name.
- Click CDN.
- Make sure to uncheck the box on the right to indicate you disable CDN.
- Save your changes.
While it isn’t usually recommended, you can also try disabling your firewalls to check if it’s interfering with opening the website. Certain host providers offer full proxy services that may include extra firewalls, which could cause a 502 bad gateway error.
If you’re using Windows 10, you can disable your firewall with the following steps. This will also disable the firewall in Google Chrome, Opera, Microsoft Edge, and Firefox.
- Open Control Panel.
- Click on System and Security.
- Select Windows Firewall.
- Select Turn Windows Firewall on or off.
- Check the icon next to Turn Off Windows Firewall (not recommended).
- Click OK to save the changes.
You can follow these steps if you’re using macOS:
- Open the Apple Menu.
- Select System Preferences.
- Click Security & Privacy.
- Click Firewall.
- Select Firewall Options to disable the firewall temporarily.
Temporarily disabling the CDN or firewall may fix the issue of the 502 bad gateway error message. If it doesn’t, you can always refer to these steps to change your settings to their original form.
Cloudflare 502 Bad Gateway Error
The Cloudflare 502 bad gateway error occurs when the server you were trying to connect to receives a bad response from another server. This can happen when a server is overloaded or experiencing some network issues between the two servers. There are two variations to the Cloudflare 502 bad gateway error.
502 Bad Gateway Cloudflare (Variation 1)
The below image indicates the problem that occurred on Cloudflare’s end. If you see this error message, you can reach out to them for support. It’s also helpful to check Cloudflare’s status page for assistance or to see if they are experiencing an outage.
502 Bad Gateway Cloudflare (Variation 2)
The next variation, as described in the image below, indicates the problem is with the hosting provider. If this happens, you can either follow the steps we’ve listed earlier in the article or get in touch with your host provider for support.
Check Your Plugins and Themes (Troubleshooting Mode)
Using third-party plugins or themes in your WordPress website can sometimes cause queries to be canceled by the server. This happens when there’s bad code on your site. You can troubleshoot this by simply disabling all your plugins and checking if your website is loading properly.
If it is, you’ll know there’s a bad plugin somewhere. You’ll need to find which one by enabling each plugin one at a time and seeing if the website loads after each one. You should always ensure your WordPress core, plugins, and themes are updated.
Take A Look At Your Error Logs
If the problem persists, you may need to further investigate what’s causing it. Error logs can be helpful when troubleshooting problems on your WordPress site. You can access your error logs by using a logging tool. In the error log, you’ll be able to see how often the 502 bad gateway error is happening to see if it is a one-time occurrence or if it requires further attention.
You can use the following steps to view the raw access and WordPress error logs via FTP:
- Connect your site via SFTP.
- You’ll see a folder named “logs” in the root folder.
- Your access and error logs will be in that folder.
If the host does not have a logging tool, you can enable this in your wp-config.php file to allow logging. WordPress features its built-in debug tool that is useful for debugging WordPress. All you have to do is enable the WordPress debug mode and WordPress debug log, then specify a custom file path where you’ll be able to access it later.
Restart PHP and Rebuild Web Application in RunCloud
You can try restarting PHP through your host settings. If your host doesn’t provide this, you can request a support ticket.
Many people also manage their servers through RunCloud, a control panel for cloud servers. It’s an easy way to build and manage web servers. If you’re encountering the 502 bad gateway error regularly, especially when you’re in the process of building your website, you can choose to rebuild your web application in RunCloud or simply reach out to us and we’ll help you out!
PHP Timeout Issue
PHP timeouts happen when one PHP process runs longer than the max_input_time or max_execution_time that has been set in your server’s PHP configuration. This is a common issue, especially when you’re conducting large WordPress imports. If you encountered the 502 bad gateway error because of PHP timeouts, then you’ll need to check and evaluate the values set in your server.
There are many issues that can cause the 502 gateway error, but there are also many ways for you to troubleshoot the issue. Most of the time, the issue will be with your host and not with the client. It’s important to remember that third-party plugins with bad codes are also common causes for the 502 gateway error. Lastly, if you’re still receiving the error after running through all the necessary steps, it may be a good idea to rebuild your web application in RunCloud.
Categories: Server Management