Oct 26, 2022
How to Fix 502 Bad Gateway Error
The reasons for 502 bad errors can be numerous, from minor browser-related issues to problems with CDNs. This article will go over some troubleshooting steps to follow when a 502 Bad Gateway error occurs, both for the server and client-side. We will also take a look at the different factors that might cause this error message, along with the impact they can have on your site’s SEO.
|Error code||502 Bad Gateway Error|
|Error type||Server-side error|
|Error variations||Temporary Error (502)|
HTTP Error 502 Bad Gateway
502 Proxy Error
Bad 502 Gateway
502 Service Temporarily Overloaded
A blank white screen
|Error causes||Unresolved domain name|
Home-network equipment error
502 Bad Gateway Error – Video Tutorial
Looking for an easy visual guide? Check the video below.
What Is a 502 Bad Gateway Error?
The 502 Bad Gateway error indicates that the server which you’re connecting to received an invalid response. When accessing a URL, your browser sends an HTTP request to the server, which in this case was invalid, returning an HTTP 502 status code.
Browsers and servers interact with each other using HTTP (HyperText Transfer Protocol) status codes. Whenever you access a URL, the browser sends an HTTP request to the webserver of the site you’re accessing. The server then returns a status code along with the resources you requested.
HTTP status codes are grouped into five server responses:
- 1xx – informational
- 2xx – success
- 3xx – redirection
- 4xx – client error
- 5xx – server error
An HTTP status code starting with the digit “5” relates to errors that occur when there’s a network error or communication problem between web servers.
Other 5xx status codes include the 500 Internal Server Error, 501 Not Implemented, 503 Service Unavailable, and 504 Gateway Timeout. Though the exact reasons for each error vary, in most cases, the cause lies within the server.
What Causes a 502 Bad Gateway Error?
Before you can fix the Gateway error, you need to examine the potential factors causing this error, such as:
- Unresolved domain name. This happens when a domain name is not resolving to the correct IP. Keep in mind that if you have recently migrated your domain name to another host, DNS servers changes might take up to 24 hours to be fully propagated and active.
- Origin server overload. Whenever an origin server runs out of resources, it can get overloaded and crash, triggering an http error 502. A sudden spike of traffic, low memory, and software timeouts are some of the common reasons for server overload.
- Browser errors. Sometimes, a browser might show a 502 coding error despite not having server or network issues. In this case, the error might be triggered by faulty browser extensions such as ad-blockers, outdated browser versions, or corrupted files in your browser cache.
- Home-network equipment issues. If you encounter HTTP 502 Errors in more than one website or browser, there is a good chance that your network equipment might be having a temporary connection problem.
- Firewall blocks. A firewall protects your website from any suspicious traffic. However, some firewall systems are over-sensitive and might detect false positives. The system might be blocking a specific ISP or a request from a CDN.
How to Fix 502 Bad Gateway Error
Although the 502 Bad Gateway error usually relates to server-side problems, it can also be caused by misconfigurations or temporary 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.
1. Refresh the Page
The first solution is a fairly simple one – wait around for a minute or two and refresh the web page you’re on. In a lot of cases, the error comes from a sudden traffic surge.
Thus, a simple page refresh usually will do the trick. For a shortcut, Windows users can press F5 or CTRL + F5, while Mac users can press CMD + R.
2. Clear Browser Cache
If the error persists, there is a chance that your browser cache has saved outdated and corrupted files. In this case, clearing the browser cache can fix an HTTP 502 Bad Gateway error.
Keep in mind that removing cached files might risk you losing important browser data, including bookmarks and setting preferences. To prevent this, simply export your data from the browser and import it back after.
3. Try in Incognito Mode
Accessing the website using Incognito mode is also a good idea as it helps determine whether the HTTP Error 502 message appears due to a browser-related issue. To open an Incognito window, click on the three-dots button on your browser screen and choose New Incognito Window.
If the error doesn’t occur in Incognito mode, the problem might be caused by a browser extension.
With that in mind, try to disable your add-ons or extensions gradually. Once you delete the one causing the error, you should be able to access the website.
If disabling extensions doesn’t help, try opening a new browser session. For example, if you’re currently on Google Chrome, try using Mozilla Firefox.
When the page loads normally on the new browser, your previous browser might be causing the error. To solve the problem, try deleting and reinstalling your faulty browser.
4. Flush DNS Servers
The error can also occur due to DNS problems, such as incorrect IP addresses and unresponsive DNS servers.
In this case, flushing your DNS cache can be the answer. This method works similarly to clearing your browser’s cache. It will remove faulty files from your DNS server.
Temporarily changing your DNS servers is another step you can take. By default, your DNS servers are assigned by your ISP. However, you can always change it to a third-party server, such as Google Public DNS.
5. Test on Another Device
If none of the above solutions fixed the HTTP error 502, test the connection on another computer or a mobile device, preferably connected to a different network.
Try restarting your PC and other networking equipment. To do so, turn off your computer and unplug your wireless router. Wait for a moment and plug them back on.
This step helps decide whether the error is related to your networking equipment or if the problem lies elsewhere.
6. Check Error Log
When you experience an error after a particular change or update, the fault may lie within your server itself. The best approach to this issue is to check your website error log.
Usually, your hosting service gives access to enable website error log through an admin dashboard. You can also enable error logging on your WordPress site by adding the following lines in wp-config.php:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
All of the generated errors will appear in the wp-contents/debug.log file, allowing you to detect which ones are causing a 502 Bad Gateway error.
7. Check Plugins and Themes
Sometimes, faulty plugins or themes can be one of the reasons for the error.
This is because poorly coded plugins and themes can conflict with each other. When this happens, your server will stop every script and query on your website, making it inaccessible.
For some websites, the issue usually comes from caching or security plugins. There is a good chance that these plugins block communication between servers, causing the error to persist.
If you don’t have a caching or security plugin installed but still encounter an HTTP 502 Error, it’s best to disable your plugins and re-activate them one by one. To do so, go to Plugins and simply click Deactivate from the Bulk Actions menu.
Then, activate each plugin while refreshing your WordPress site after each one. Once the 502 Error pops up again, you have found the problem plugin.
However, if you can’t access your WordPress dashboard, you can try disabling them from your hosting panel or FTP program. Navigate to the wp-content directory and rename the plugins directory, for example, plugins-disable.
If you use Hostinger, access your hPanel and click on Files. From there, go to File Manager -> public_html -> wp-content.
Once your site starts working after all plugins are disabled, you may rename the folder back to plugins. Then try enabling 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.
8. Check CDNs
Another cause of the 502 Bad Gateway errors can be problems with your CDN or DDoS mitigation services.
A content delivery network adds an extra layer between your server and browser to efficiently deliver web content. However, this layer can run into an issue when connecting with your origin server, resulting in 502 Errors.
One notable example would be Cloudflare, where the 502 Bad Gateway can occur in two different variations depending on the issue.
The screen above indicates that the issue is on Cloudflare’s side. To fix it, you’ll need to reach out to their customer support team. Remember to check the Cloudflare System Status page before doing so.
Alternatively, you may choose to disable Cloudflare, though keep in mind that your DNS propagation may take a couple of hours.
However, if you see the Cloudflare error shown above, it means that the issue lies with your current hosting provider. In this case, try to contact your web host support team and ask for assistance.
9. Check the Site Status
If the 502 Error code is still showing up despite trying most of the methods so far, it is possible the origin server might be currently experiencing a downtime.
10. PHP max_execution_time and max_input_time
PHP timeout happens whenever a PHP process loads for more than the specified max_execution_time or max_input_time. These are the values set in your PHP configurations on your web server. Usually, the values are set to 300 seconds by default.
A timeout can happen during the migration process and trigger a 502 Bad Gateway error. To fix this issue, you can talk to your web host to check what your values are set at and if you can increase them.
11. Contact Customer Support
If none of the above solutions fixed the error, it’s best to contact the customer support team.
While describing the issue, try to include what troubleshooting steps you have taken. Provide as much information as possible, and let the support team assist you.
502 Bad Gateway Error Variations
The error can appear on any browser, operating system, and service. However, its appearance varies in different ways. Here are some alternatives that you might encounter on the web:
- Temporary Error (502)
- 502 Error
- Error 502
- HTTP Error 502 Bad Gateway
- 502 Server Error: The server encountered a temporary error and could not complete your request
- 502 – Web server received an invalid response while acting as a gateway or proxy server
- HTTP 502
- 502 Proxy Error
- Bad 502 Gateway
- 502 Service Temporarily Overloaded
- 502 Bad Gateway Nginx
- A blank white screen
Keep in mind that some websites or services have custom 502 Error pages and will look different, for example:
Chrome’s 502 Bad Gateway error screen tells you that the server encountered a temporary error and could not complete your request. Chrome also suggests trying it again in 30 seconds. If the problem continues, try accessing the site from different browser windows.
GitLab serves a 502 Bad Gateway error when its reverse proxy server doesn’t receive a response from GitLab’s origin server for an extended period. The error page also displays instructions to solve the issue.
Twitter has its own way of displaying a 502 service temporarily overloaded error. It incorporates a playful illustration with a clear-cut message. Users can also check out the Twitter Status page for real-time data statistics.
How 502 Bad Gateway Error Affects SEO
A 502 Error code appears when your server experiences a networking error that prevents it from completing a request. If this error keeps happening regularly and for an extended period of time, it can have a negative impact on your website SEO.
When a requested page is not served, visitors will be more likely to leave your site, resulting in a poor user experience. Moreover, the longer your site is unavailable, the higher your bounce rate will be.
Similar to human visitors, search engine crawlers also see a page with a 502 Error as broken, which prevents them from indexing and ranking the page.
With that in mind, it is crucial to investigate the factors causing the error and fix it as soon as possible for the sake of SEO.
Error Status Codes Similar to 502 Bad Gateway
Understanding error codes are important for website owners and developers to identify and fix the problem quickly. Aside from HTTP 502 Errors, there are other status error codes that your website may encounter.
The most common ones include:
- 403 Forbidden Error. Occurs when the webserver restricts visitors from accessing specific content.
- 404 Page Not Found. Refers to a response sent whenever the requested web page is not available.
- 501 Not Implemented. This indicates that the server doesn’t have the functionality to fulfill a certain request.
- 503 Service Unavailable. This shows that the server is currently down due to maintenance and fails to process the request.
- 504 Gateway Timeout. Appears as a result of proxy error when one waits too long for a response from the upstream server.
A 502 Bad Gateway happens when a server that functions as a gateway receives an invalid response from the origin server. If left untreated, this error will impact your conversion rate, the user experience, and page rankings.
As the status code suggests, the root of this error usually lies on the server-side. In other words, the problem doesn’t come from your website, internet connection, or computer. With that in mind, it is also important to keep an eye out for broken plugins or themes.
We hope these troubleshooting steps help you remove any errors you might run into and return your site to a stable condition. If you have any extra tips or solutions, feel free to share them with us in the comments below.
502 Bad Gateway FAQ
Why Do I Get a 502 Bad Gateway Error?
502 Bad Gateaway Error is a generic error indicating that something is not quite right with the website’s server communication. It won’t tell you exactly what’s wrong, though.
Is 502 Bad Gateway a Virus?
502 Bad Gateaway Error is not a virus – it’s an error message that is often the result of issues with communication with a website’s server.