How to Fix 502 Bad Gateway Error

How to Fix 502 Bad Gateway Error

The 502 Bad Gateway error is one of the most common errors that a WordPress site might run into during its lifetime. 502 error happens when the server fails to send responses to a client’s request, making the site unavailable. The reasons can be numerous, from minor browser-related issues to problems with CDNs.

This article will go over the troubleshooting steps to follow when 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 the error, along with the impact they can have on your site’s SEO.

What Does 502 Bad Gateway Mean?

cloudflare 502 error

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
A graphical illustration showing how a 502 bad gateway occurs.

HTTP status codes starting with the digit “5” relate to errors that occur when there’s a network error or communication problem between web servers. A 502 Bad Gateway error occurs when a server acting as a gateway or proxy receives an invalid response from the origin server.

Other 5xx status codes or server errors 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. 

Error code502 Bad Gateway
Error typeServer-side
Error variationsHTTP Error 502 – Bad Gateway
502 Proxy Error
502 Service Temporarily Overloaded
502 Bad Gateway NGINX
Error 502
Temporary Error (502)
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
A blank white screen
Error causesUnresolved domain name
Origin server overload.
Browser errors
Home-network equipment issues
Firewall blocks

Causes of 502 Bad Gateway Error

Before you can fix a 502 Bad 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, your DNS 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 a 502 Error. 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 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 a 502 Error 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 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 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

You can also try checking if the website is offline using an online tool, such as Website Planet or Host Tracker. This will help identify whether a server or a client-side issue causes the error.

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 a 502 Bad Gateway error.

Keep in mind that removing cache 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 502 Error 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.

open incognito mode from browser

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 different browser. 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

The 502 Bad Gateway 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 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 502 Bad Gateway error, 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 a 502 Bad Gateway 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 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 a 502 Bad Gateway 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 a 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.

wordpress dashboard deactivating plugins

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. 

hpanel renaming plugins to disable

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 a 502 Error.

One notable example would be Cloudflare, where the 502 Bad Gateway can occur in two different variations depending on the issue.

cloudflare 502 error

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.

502 bad gateway error

However, if you see the version of the 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 is still showing up despite trying most of the methods so far, it is possible the origin server might be currently experiencing a downtime. 

Luckily, there are many tools on the web to examine if a site is down, including Down for Everyone or Just Me and IsItDown. Simply input your URL and check the status of your website.

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 webserver. 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 502 Bad Gateway 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

A 502 Bad Gateway 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

Google chrome 502 error

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

Gitlab 502 error

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

Twitter 502 error

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 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 a 502 Server 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 502 Errors, there are other status error codes that your website may encounter. 

The most common ones include:

  • 301 Permanent Redirect. Happens when the requested page has been moved to a new location. Visitors and search engine crawlers will be redirected to the new URL.
  • 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 another server.

Conclusion

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.

 

Author
The author

Nabilla R.

Nabilla is a WordPress expert and a digital content writer at Hostinger. When she's not busy writing, she loves to explore nature.