How to Fix “502 Bad Gateway" Error?
Table of Contents
Sometimes when you try to visit a site, your browser may load the “502 Bad Gateway” HTTP error page. This error is quite general and it doesn’t provide much information about the actual cause, so you may wonder where to begin in order to fix it.
In the following guide, we examine what is the error “502 Bad Gateway”, what are the common causes, and possible solutions.
Usually, when you open a webpage, your browser sends an HTTP request to the server of the website. The hosting server then processes the request, returns a response, and displays the webpage in your browser. When everything is in order, the HTTP response code is 200(OK). Your browser displays the webpage properly and you don’t see any status code.
However, when there is a problem, the webpage’s hosting server can’t process your request. You will see an error page with an error code indicating the cause.
The most common error codes can be categorized into two major groups:
- 4XX codes – client-side errors, indicating that your browser sends an invalid request to the server
- 5XX codes – server-side errors, indicating that the webpage’s server can’t provide a valid response
In other words, the servers communicating to display the site for you can’t establish a connection. This could be the result of high traffic to the website, temporary connectivity issues from your network or device, or website-related errors. The usual result is that you can’t load the requested page. Instead, your browser displays an error page, showing the “502 Bad Gateway” Error.
The look of the page may vary. Depending on the website’s hosting server and proxy services it uses, you may see a different-looking “Bad Gateway Error 502” screen. Below, you can see some examples:
The image above shows a “502 Bad Gateway NGINX” error from a server using NGINX as a reverse proxy, which is a very common web-server setup.
The error page may be further customized by some hosting providers. Below you can see an example of a customized “502 Bad Gateway” Error page:
As you can see, the error pages don’t provide much information about the actual issue. Thus, you may need to troubleshoot the problem further. In the following section, we examine the most common causes of the 502 Bad Gateway error.
Common Causes of 502 Bad Gateway Errors
1. Overloaded Servers
Imagine a busy highway during rush hour—traffic jams can cause delays, just like overloaded servers struggling to handle incoming requests. When servers reach their capacity, they may fail to process requests, resulting in the 502 Bad Gateway error.
2. Proxy Server Issues
Proxy server issues, such as misconfigured proxies or proxy timeouts, can disrupt communication between clients and servers. Like a mistranslated conversation, proxy server issues can lead to misunderstandings and trigger the 502 Bad Gateway error.
3. DNS Misconfigurations
DNS misconfigurations, such as incorrect DNS records or DNS server failures, can prevent clients from resolving domain names to IP addresses. Like sending a letter without the correct address, DNS misconfigurations can result in the 502 Bad Gateway error.
4. Backend Server Failures
Backend server failures, including hardware failures or software crashes, can render servers unable to fulfill client requests. Like a chef burning the main course, backend server failures can lead to service disruptions and trigger the 502 Bad Gateway error.
Impact of the 502 Bad Gateway Error
1. Negative User Experience
Encountering a 502 Bad Gateway error can frustrate users and disrupt their browsing experience. Like hitting a pothole on a smooth road, encountering this error can jolt users out of their flow and leave a negative impression of your website.
2. Potential Loss of Website Traffic
Unresolved 502 Bad Gateway errors can deter users from returning to your website, leading to potential loss of website traffic. Like encountering a closed store during business hours, users may seek alternative sources for the information or services they were seeking.
3. Impact on SEO Rankings
Frequent 502 Bad Gateway errors can negatively impact your website’s search engine rankings. Search engines prioritize websites that offer a seamless user experience, and encountering errors can signal to search engines that your website may be unreliable or poorly maintained.
How To Fix “502 Bad Gateway” Error and What Are The Causes?
Even though the definition of “502 Bad Gateway” error points out that the issue is from the website’s server, there are various reasons that can cause the error. They can range from an ongoing problem on the website’s hosting server, to connectivity issues from your Internet Service Provider (ISP) or even local DNS errors from your local device.
Here are the most common causes and the possible ways to resolve them.
Temporary connectivity issue
Sometimes, a brief moment of high traffic spike on your network or the website’s hosting server can cause the error.
Usually, such downtime is very short and the error goes away instantly. But you may have opened the website at the exact moment when it was unresponsive.
One of the quickest and easiest ways to find out if the error is gone is to reload the page. You can easily reload the page with the key combination F5 (Control+F5) for Windows or Command+R for Mac.
You may also use the Reload button in your browser. Each browser has a Reload button next to the address bar. For example, you can see the button in Chrome in the following screenshot.
If the website loads after the page is reloaded, you can conclude the error was only momentary and keep browsing.
If reloading the page didn’t fix the issue, you may consider opening the page from another browser. The issue may be specific to the browser you are using and the page might open properly from another one. For instance, if you’ve been using Google Chrome so far, try to open the page from Mozilla Firefox or Microsoft Edge.
If the “502 Bad Gateway” error is not present in another browser, this is a strong indication that the problem is with the browser you’ve been using. You can then proceed to troubleshoot by clearing the browser’s cache and cookies.
Expired browser cache and cookies
To improve the browsing experience, modern web-browsers cache the websites’ resources locally on your device. This allows you to open a website much faster the next time you visit it because the website assets have already been downloaded on your local machine. However, your browser may have saved expired or corrupted cache or cookies which lead to a “502 Bad Gateway” error.
Clearing the browser’s cache and cookies is a simple and quick task that can save you a lot of time for troubleshooting. The exact process varies depending on your browser or device. You can see detailed instructions on how to clear the cache and cookies for your device or browser here:
- How to Clear Cache and Cookies for your desktop browsers
- How to Clear Cache and Cookies for Android
- How to Clear Cache and Cookies for iOS
Browser plugins and extensions
Another possible cause of the “502 Bad Gateway” error may be a plugin or extension in your browser. They may interfere with the connection established between your browser and the website’s server, and cause the error. You may consider disabling them for the sake of troubleshooting.
Let’s take Google Chrome, for example. Navigate to the top-right corner and select the kebab menu. It will open a drop-down menu. Select More Tools. Then, choose Extensions.
This will open the page where the extensions for Chrome are installed. Each extension has a slot with a blue switch. It indicates that the extension is enabled. By clicking on it, the switch will become gray, which will indicate that the extension has been disabled.
You may first disable all extensions. If the “502 Bad Gateway” error goes away, this means that one of the extensions had caused the issue. You can proceed and enable them one by one.
When the culprit is activated again, the error will most likely return. Thus, you will find out which extension caused the error in the first place.
Each browser has a similar page to Chrome’s, where the extensions are controlled. You may proceed and test disabling the extensions for your particular browser application.
Corrupted DNS or other settings from your device
Another possible cause of the “502 Bad Gateway” error may be an outdated DNS cache from your local device. To speed up the DNS lookup, your computer stores DNS settings locally. In general, this improves the browsing experience.
However, if there was a DNS change for the website’s domain, your local DNS cache may store outdated information. This may result in the “502 Bad Gateway” error.
This is why it is recommended to clear your local DNS cache. Depending on your OS (operating system), the process varies. You can see detailed steps for the most common OS systems below:
- How to Clear DNS Cache for Mac OS
- How to Clear DNS Cache for Windows
- How to Clear DNS Cache for Linux
There is a small chance that your router or computer keeps other outdated settings. Restart your network router and your computer as this may fix the issue.
Internet Service Provider (ISP) connectivity issues
The “502 Bad Gateway” error can also be caused by a temporary connectivity issue originating from your local ISP. There may be various reasons – high traffic on their network, a problem that prevents the ISP’s network from connecting to the website’s network, etc.
What you can do is change the network that your device uses. For instance, if you use a mobile device on a Wi-Fi network, you can test by switching to a mobile 3G/4G/5G network. If you use a desktop, you can use your phone as a hotspot and connect to its mobile network.
If the error goes away, it is safe to assume this was a temporary connectivity issue from your network.
It is a good idea to contact your ISP so they can check the connection to the website’s address. They may already be aware of the problem and working on it.
Issues originating from CDN or Firewall Services
Nowadays, many websites use CDN (Content Delivery Network) services and proxy firewalls. These improve the websites’ performance and security. Cloudflare CDN and Sucuri Firewall are some examples of such services.
Although they are very reliable, they are not immune to errors just like any web-based service. When there is extremely high traffic on their networks, a website may show the “502 Bad Gateway” error.
If your site uses such services, one of the first things to check is to disable the CDN or firewall for your domain.
Every CDN or firewall service has a control panel where you can manage its settings. Log in to the control panel and test pausing or temporarily disabling the service.
If the page for the “502 Bad Gateway” error disappears after you stopped the service, it is an indication that the CDN or firewall is the problem. Keep the service disabled for the time being.
You may consider contacting its support team to get more information about the issue. Once the problem is solved, you can activate the service again.
PHP and other errors from the website
Sometimes, the error can be caused by a misconfiguration of the website’s application. The reasons can be conflicts between PHP scripts, an incorrect PHP version for the website, timeouts from CGI scripts, slow MySQL queries, etc.
Change the PHP version of the website
A common cause of PHP errors is an incorrect PHP version set for the website. You may have switched the PHP version, updated your website core files, installed a new plugin or theme, or updated an existing one. The present setup of the website may not be compatible with the PHP version your site uses.
Most hosting providers provide tools to easily switch between PHP versions. SiteGround users can use Site Tools’s PHP Manager to change the PHP version with just a few clicks. For more instructions, check this guide on how to switch to a different PHP version.
After the PHP version is changed, try to reload the page. If the error is gone, it means the error was caused by the incorrect PHP version.
For WordPress websites, a common cause is that the plugins or the theme are not compatible with the previous PHP version. If the previous PHP version was higher, you could examine if there is an update for the theme and the plugins. Check if the new update is compatible with the higher PHP version so you can test switching the PHP version again.
Examine the website’s error logs
If switching the PHP version didn’t fix the issue, the error may be related to a specific file or a setting in the website.
When the cause of the “502 Bad Gateway” error originates from the website, there should be an indication of the problem.
The majority of popular website applications have the functionality to report errors in an error log.
For example, you can enable an error log for your WordPress site. You can check the detailed instructions on how to enable debugging from this guide.
From the error log, you can see which files cause a PHP error so you can examine them.
Another method is to use your web hosting’s control panel. Errors detected by the server are registered in an error log, part of the hosting tools.
SiteGround users can access the website’s error logs from Site Tools. Navigate to the section Statistics, then open the section Error Log.
You can see the errors registered by the server. You can explore if the error is related to the “502 Bad Gateway”. The error will also indicate the file related to the error so you can explore it further.
Errors caused by plugins for WordPress websites
The “502 Bad Gateway” error may also be caused by a corrupted or misconfigured plugin, causing a timeout or a conflict with another plugin. You may consider disabling the plugins to see if the error message will disappear.
If the error is gone after the plugins are disabled, you can then enable them one by one. When the faulty plugin is enabled the error will most likely return. You may consider replacing the plugin with an alternative one, providing the same functionality, or contacting the plugin’s support.
Disable the plugins from the WordPress dashboard
To disable the plugins, open your WordPress website’s dashboard. Then, go to the Plugins section, then Installed Plugins. Select Deactivate from the Bulk actions drop-down menu.
Then check the box for Plugins and press Apply.
This is the standard procedure for deactivating the plugins when you have access to the dashboard.
Disable the plugins from the database of the website
In many cases, the ongoing error prevents you from logging in to the dashboard. In such cases, you can disable the plugins from the website’s database.
You can find detailed instructions in this guide.
Disable the plugins from Site Tools
SiteGround users can also use Site Tools’s WordPress->Install and Manage section to disable all plugins with a single click. For detailed instructions, read this guide.
Hosting provider issues
It is also possible that the error is not originating from the website or your local network. The hosting server of the website may be overloaded or experiencing a more specific setup issue.
If none of the solutions helped solve the “502 Bad Gateway” error, you can consider contacting the web hosting provider that can check the server’s status and help fix the issue.
They may be aware of the problem and already working to resolve it.
Summary
The “502 Bad Gateway” error could be due to local connectivity problems, misconfigurations from the website, or server issues. Troubleshooting the error may be cumbersome, but we hope this guide points you in the right direction.
“502 Bad Gateway” is one of the many different HTTP status codes.
Read more about the various errors in these suggested topics: