What is it and How to Solve the 502 Bad Gateway Error

A mistake 502 Bad Gateway occurs when a server acting as a gateway or proxy receives an invalid response from the origin server. This makes the site unavailable. The reasons can be numerous, from minor browser-related issues to issues with CDNs.

In this article, we will go over the steps to take to fix the 502 Bad Gateway error, both on the server and client side. We’ll also take a look at the different factors that can cause the error, along with the impact they can have on the .

Browsers and servers interact with each other using HTTP (HyperText Transfer Protocol) status codes. Every time you access a URL, the browser sends an HTTP request to the web server of the site you are accessing. The server returns a status code along with the requested resources.

HTTP status codes are grouped into five responses from the server:

  • 1xx – informative
  • 2xx – correct
  • 3xx – redirects
  • 4xx – client errors
  • 5xx – server errors

HTTP status codes beginning with 5 correspond to errors that occur when there is a network failure or communication problem between web servers.

Other 5xx status codes or server errors include the , 501 Not Implemented, Y . Although the exact reasons for each error vary, in most cases the cause lies with the server.

Causes of the 502 Bad Gateway error

Before you can troubleshoot the 502 Bad Gateway error, you need to examine the possible factors causing this error, such as:

  • Unresolved domain name. This occurs when a domain name does not resolve to the correct IP. Please note that if you have recently migrated your domain name to another host, it may take up to 24 hours for DNS changes to fully propagate and become active.
  • Origin server overload. When an origin server runs out of resources, it can become overloaded and crash, causing a 502 error. A sudden spike in traffic, low memory, and software downtime are some of the most common reasons for server overload.
  • browser errors. Sometimes a browser may display a 502 error despite not having server or network issues. In this case, the error can be caused by faulty extensions such as ad blockers, outdated browser versions, or corrupted cache files.
  • Home network equipment problems. If you experience a 502 error on more than one site or browser, it’s very likely that your network equipment is having a temporary connection problem.
  • firewall blocks. A firewall protects your website from any suspicious traffic. However, some firewall systems are too sensitive and can detect false positives. The system could be blocking a specific ISP or a request for a .

How to fix the 502 Bad Gateway error

Although the 502 Bad Gateway error is usually related to server-side issues, it can also be caused by misconfigurations or client-side issues. Therefore, we are going to go through the most common steps to solve the problem taking into account both causes.

See also  WordPress SEO: Position your site in 5 steps

Although some solutions focus on WordPress, most of them can be applied to any site.

1. Refresh the page

The first solution is quite simple. Wait a minute or two and refresh the page you’re on. In many cases, the error is temporary and a simple page refresh will suffice.

So a simple page refresh is usually enough. Windows users can press F5 either CTRL+F5while Mac users can press CMD + R.

Meanwhile, you can also check if the website is down with some online tool, like or . This will help identify if the cause of the error is a server or client issue.

2. Clear browser cache

If the error persists, there is a chance that a certain cached item is causing it. So it is a good way to fix 502 bad gateway error.

Please note that by clearing the cache you may lose important browser data such as bookmarks and settings preferences. To avoid it, simply from the browser and come back to later.

3. Try incognito mode

Accessing the site using incognito mode is also a good idea, as it helps determine if the 502 error message is appearing due to a browser-related issue. To open an incognito window, click the three dot button from the browser screen and choose New incognito window.

If the error does not occur in incognito mode, the issue may be caused by a browser extension.

With this in mind, try disabling your plugins or extensions gradually. Once you remove the one causing the error, you should be able to access the website.

If disabling extensions doesn’t help, try opening another browser. For example, if you are using Google Chrome, try using Mozilla Firefox.

If the page loads normally in the new browser, your old browser may be causing the error. To fix the problem, try deleting and reinstalling the failing browser.

4.Flush DNS

The 502 bad gateway error can also appear due to DNS issues, such as incorrect cached IP address values.

In such cases, it may be the answer. This method works similar to clearing the browser cache. It will remove the bad files from your DNS server.

You can also temporarily change your DNS servers. By default, your DNS servers are assigned by your ISP. However, you can always change it to a third party server, like .

5. Try on another device

If none of the above solutions resolved the 502 Bad Gateway error, try the connection on another computer or mobile device, preferably connected to a different network.

See also  How to stay inspired as a web designer

Try restarting your PC and other computers on the network. To do this, turn off your computer and unplug your wireless router. Wait a moment and reconnect them.

This step helps you decide if the error is related to your network equipment or if the problem is somewhere else.

6. Check the error log

If the 502 Bad Gateway error appeared after a certain change or update, it is possible that the error is within the website. The best way to approach it is to find suggestions.

Typically, the hosting service provides access to enable site error logging in the admin panel. In WordPress, you can enable error logging by adding the following lines in :

define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_LOG’, true ); define( ‘WP_DEBUG_DISPLAY’, false );

All errors generated will appear in the file wp-contents/debug.logallowing you to detect which ones cause a 502 Bad Gateway error.

7. Review 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 your website’s scripts and queries, making it inaccessible.

On some websites, the problem usually comes from caching or security plugins. These plugins are most likely blocking communication between the servers, causing the error to persist.

If you don’t have any caching or security plugins installed but you still get a 502 error, it’s best to disable your plugins and re-enable them one by one. For this, go to pluginsselect all and click Deactivate in the menu of batch actions.

Then activate each plugin and update your WordPress site after each one. When the 502 error appears again, you have found the problematic plugin.

However, yes, you can try to disable them from your hosting panel or FTP program. Navigate to the directory wp-content and change the name of the plugins directory, for example, plugins-disable.

If you use , sign in to your hPanel and click Records. From there, go to File Manager -> public_html -> wp-content.

If the site starts working after all plugins are disabled, you can rename the folder to plugin again and enter it. It then tries to disable the plugins one by one to determine which one caused the error first.

If the site still doesn’t work, follow the same steps with your WordPress themes.

8. Check CDNs

Another cause of the 502 Bad Gateway error can be the CDN’s or mitigation services DDoS.

See also  How to Create a PayPal Donation Button in WordPress

A content delivery network adds an additional layer between the server and the browser to efficiently deliver web content. However, this layer may have problems connecting to its origin server, resulting in a 502 error.

A notable example would be cloudflarewhere the 502 Bad Gateway can occur in two different variations depending on the problem.

This screen indicates that the problem is on CloudFlare’s side. To solve it you will have to contact your customer service team. Remember to check before doing it.

Another option is to opt to disable CloudFlare, but keep in mind that DNS propagation can take a couple of hours.

But if you see the version of the error shown above, it means that the problem lies with your current hosting provider. In this case, contact the support team of your web hosting provider and ask for help.

9. Check the site

If the 502 error continues despite trying most of the above methods, your origin server may be experiencing downtime.

There are many online tools to check if a site is down, but a good one to use is or . Simply enter your URL and check the status of your website.

10. max_execution_time and max_input_time in PHP

PHP idle time occurs whenever a PHP process takes longer to load than the specified max_execution_time or max_input_time. These are the values ​​set in the PHP configuration on your web server. Typically, the values ​​are set to 300 seconds default.

During the downtime, a 502 Bad Gateway error may occur. To fix this issue, you can talk to your web host to see what values ​​you have set and if you can increase them.

11. Contact Customer Service

If none of the above solutions fixed the 502 Bad Gateway error, then it’s best to contact .

When describing the problem, try to mention the steps you took to fix the problem. Provide as much information as possible and let the team assist you.

Variants of the 502 Bad Gateway error

A 502 Bad Gateway error can appear in any browser, operating system, and service. However, its appearance varies in different ways. Here are some alternatives you can find on the web:

  • Temporary Error (502)
  • 502 error
  • Error 502
  • HTTP Error 502 Bad Gateway
  • 502…
Loading Facebook Comments ...
Loading Disqus Comments ...