Choose another country or region to see content specific to your location and shop online.
United States
USA

How to Fix 502 Bad Gateway Error

Picture of William Bacchus
William Bacchus

Published: October 6, 2023

Last updated: October 6, 2023

Table of Contents

how to fix the 502 bad gateway error

Understanding and resolving website errors is an essential skill for any website owner or developer. The 502 Bad Gateway error is a common issue that can disrupt a website’s functionality and user experience. This guide will delve into the causes of this error and provide step-by-step solutions to fix it.

What does the 502 Bad Gateway Error mean?

The 502 Bad Gateway error is an HTTP status code signifying a communication error between two servers. The server you’re attempting to connect to has received an invalid response from an upstream server. This error can be due to a variety of reasons, including server overloading, network connectivity issues, DNS problems, or website configuration issues.

HTTP status codes are divided into five categories:

  • 1xx: Informational
  • 2xx: Successful
  • 3xx: Redirection
  • 4xx: Client Errors
  • 5xx: Server Errors

The 502 error falls under the 5xx category, which denotes server errors. Other 5xx status codes include 500 Internal Server Error, 503 Service Unavailable, and 504 Gateway Timeout.

Common Causes of the 502 Bad Gateway Error

The 502 Bad Gateway error can be caused by a number of factors:

  • Unresolved Domain Name: This occurs when a domain name fails to resolve to the accurate IP address. It’s essential to remember that if you’ve recently transferred your domain name to a different hosting provider, it could take up to 24 hours for DNS server changes to propagate completely and become fully active.
  • Server Overload: When an origin server exhausts its resources, it can become overwhelmed and crash, leading to the occurrence of an HTTP error 502. Server overload can be brought about by various factors, including a sudden surge in traffic, insufficient memory, and software timeouts.
  • Browser Errors: Occasionally, a browser may display a 502 error code even when there are no server or network problems. In such instances, the error could be initiated by problematic browser extensions like ad-blockers, outdated browser versions, or corrupted files within your browser’s cache.
  • Network Equipment Issues: If you come across HTTP 502 Errors on multiple websites or browsers, there’s a strong possibility that your network equipment is experiencing a temporary connectivity issue.
  • Firewall Blocks: A firewall serves as a safeguard for your website against potentially harmful traffic. Nevertheless, certain firewall systems can be overly cautious and may generate false positive detections. This can result in the system blocking legitimate requests from specific Internet Service Providers (ISPs) or Content Delivery Networks (CDNs).

How to Fix the 502 Bad Gateway Error

While the 502 Bad Gateway error typically stems from server-side issues, it can also result from misconfigurations or temporary problems on the client side. Therefore, we will provide a comprehensive overview of common troubleshooting steps, considering both potential causes.

Although certain solutions are tailored to WordPress, the majority of them are applicable to any website:

Refresh the Page

The initial solution is rather straightforward – wait for a minute or two and then refresh the web page you are currently viewing. In many instances, this error arises due to a sudden influx of traffic.

In such cases, a simple page refresh often resolves the issue. To expedite this process, Windows users can press F5 or CTRL + F5, while Mac users can use CMD + R.

Another useful step is to verify the website’s status using online tools like Website Planet or Host Tracker. This can help pinpoint whether the error is stemming from server-related or client-side issues.

is your website down

Clear Browser Cache

Should the error persist, there’s a possibility that your browser’s cache has retained outdated and corrupted files. In such instances, resolving an HTTP 502 Bad Gateway error can often be achieved by clearing the browser cache.

It’s important to note that clearing cached files may entail a risk of losing vital browser data, such as bookmarks and personalised settings. To safeguard against this potential loss, consider exporting your data from the browser before clearing the cache and then re-importing it once the cache is cleared.

Try in Incognito Mode

Utilising Incognito mode is a useful approach to assess whether the HTTP Error 502 message is linked to browser-related problems. To open an Incognito window, simply click on the three-dot icon located on your browser’s screen and select “New Incognito Window.”

If the error doesn’t occur in Incognito mode, it’s possible that a browser extension is responsible for the issue. If this be the case, consider disabling your extensions one by one. Once you identify the one causing the error, you should regain access to the website.

If the webpage loads without errors in the new browser, it’s likely that your previous browser is the culprit. To address the issue, consider uninstalling and then reinstalling the problematic browser.

Flush DNS Servers

The error may also be a result of DNS issues, including incorrect IP addresses and unresponsive DNS servers.

In such scenarios, resolving the problem can involve flushing your DNS cache. This process is akin to clearing your browser’s cache, as it eliminates problematic files from your DNS server.

Another potential step to consider is temporarily altering your DNS servers. Typically, your ISP assigns your DNS servers, but you have the option to switch to a third-party server like Google Public DNS.

Test on Another Device

If none of the previously mentioned solutions have resolved the HTTP error 502, consider testing the connection on an alternate computer or a mobile device, preferably connected to a different network.

Additionally, attempt to resolve the issue by restarting your PC and other networking equipment. To do this, power off your computer and unplug your wireless router. Wait for a brief moment before plugging them back in.

Taking these steps can assist in determining whether the error is linked to your networking equipment or if the issue originates elsewhere.

Check Error Log

If you encounter an error following a specific change or update, the source of the problem might reside within your server. The most effective way to address this concern is by examining your website’s error log.

Typically, your hosting service provides access to enable the website error log via an admin dashboard. You can also activate error logging on your WordPress site by inserting the following lines into the wp-config.php file:

define( 'WP_DEBUG', true );  
define( 'WP_DEBUG_LOG', true );  
define( 'WP_DEBUG_DISPLAY', false );

All of these errors will appear in the wp-contents/debug.log file, allowing you to work out which ones are causing the 502 Bad Gateway error.

Check Plugins and Themes

At times, the HTTP error may stem from problematic plugins or themes. This can occur because poorly-coded plugins and themes may clash with each other, leading to a disruption of scripts and queries on your website, rendering it inaccessible.

In some cases, caching or security plugins are the culprits behind such issues. These plugins can potentially impede communication between servers, resulting in the persistence of the error.

If you do not have caching or security plugins installed but still encounter an HTTP 502 Error, it’s advisable to deactivate your plugins and then reactivate them one by one. To do this, navigate to the Plugins section and click on “Deactivate” from the Bulk Actions menu.

Then, activate each plugin while refreshing your WordPress site after each one. Once the 502 Error appears again, you have located the problematic plugin.

Check CDNs

502 Bad Gateway errors can also be attributed to issues with your CDN (Content Delivery Network) or DDoS (Distributed Denial of Service) mitigation services.

A content delivery network introduces an additional layer between your server and the browser, optimizing the delivery of web content. However, this intermediary layer can encounter problems when establishing a connection with your origin server, leading to the occurrence of 502 Errors.

A good example is Cloudflare, where the 502 Bad Gateway error can manifest in two distinct variations, contingent on the underlying issue.

The displayed screen suggests that the problem resides within Cloudflare’s infrastructure. To resolve this issue, it’s necessary to contact Cloudflare’s customer support team. Before reaching out to them, it’s advisable to consult the Cloudflare System Status page for any updates.

As an alternative, you have the option to disable Cloudflare temporarily. However, please be aware that DNS propagation may require a few hours to complete.

Another example is if you encounter the Cloudflare error displayed above, it indicates that the problem is rooted in your existing hosting provider’s infrastructure. In such a scenario, we recommend reaching out to your web hosting provider’s support team and requesting their assistance.

Check the Site Status

If you continue to encounter the 502 Error code despite attempting most of the previously mentioned methods, there is a chance that the origin server might be currently undergoing a downtime.

Fortunately, there are numerous online tools available to check whether a website is experiencing downtime. Some options include “Down for Everyone or Just Me” and “IsItDown.” You can simply enter your URL into these tools to assess the status of your website.

PHP max_execution_time and max_input_time

PHP timeouts occur when a PHP process runs for a duration exceeding the defined max_execution_time or max_input_time limits. These settings are configured within your PHP settings on your web server, with the default values typically set at 300 seconds.

During the migration process, a timeout can occur, leading to the generation of a 502 Bad Gateway error. To address this problem, you can engage with your web hosting provider to verify your current settings and explore the possibility of increasing these values if necessary.

Contact Customer Support

If all else fails, reaching out to your hosting provider’s customer support can help resolve the issue. If you’re an Elite customer experiencing this issue, you can enjoy 24/7 dedicated customer phone support from an award-winning team.

502 Bad Gateway Error Variations

The 502 Bad Gateway error can appear differently depending on the browser, operating system, and service used. Some variations of the error include ‘HTTP Error 502 Bad Gateway’, ‘502 Proxy Error’, and ‘502 Service Temporarily Overloaded’.

How 502 Bad Gateway Error Affects SEO

Regular and prolonged instances of the 502 error can negatively impact your website’s SEO. Search engine crawlers view pages with the 502 error as broken, which can prevent them from indexing and ranking the page.

Similar Error Status Codes to 502 Bad Gateway

Aside from the 502 error, there are other status error codes that your website may encounter, such as 403 Forbidden Error, 404 Page Not Found, 501 Not Implemented, and 503 Service Unavailable.

Conclusion

The 502 Bad Gateway error is a common issue that can disrupt your website’s functionality. Understanding why it happens and how to resolve it can help you maintain a smooth user experience.

Sign up for free news, tips & offers

Your email is safe with us, we don't spam.

Picture of William Bacchus
William Bacchus
Will joined the Elite team in 2021. He has a background in content writing as well as a keen interest in media journalism. His interests include taijutsu and a immense passion for film and television. He aims to inform as many people as he possibly can about the vast and often confusing nature of web design!

Leave a Reply

Your email address will not be published. Required fields are marked *

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Sign up to our newsletter for the latest news + a Free WordPress Guide

NEWSLETTER