How to Fix a 502 Bad Gateway Error (11 Solid Solutions)

A 502 Bad Gateway Error is one of the most common WordPress errors. Every blogger faces it at some stage, in fact, giants like Google, Twitter, Gmail, and Cloudflare also encounter this same error.

There are a lot of things that can trigger 502 Bad Gateway error, but some of the most common ones are server overload, DNS issue, CDN issue, and Browser error.

In this tutorial post, we are gonna look at some of the most effective ways to quickly fix 502 Errors. So, stick till the end to grab complete knowledge.

What is a 502 Bad Gateway Error?

According to Mozilla, The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server while acting as a gateway or proxy, received an invalid response from the upstream server.

Let’s understand it in simple terms. When we open a page of a website, the browser sends a request to the server, if everything is okay, the server sends resources along with an HTTP status code.

These HTTP status codes aren’t visible to us unless something goes wrong.

When we see a 502 error, then it means that the server has encountered some problem.

With these status codes, the server informs us about what we need to do in order to fix this issue.

But the problem with the 502 error is that we don’t get much information about what went wrong.

We just get a message that says “Bad Gateway”, that’s why loving this error is tricky compared to its other family members 500, 501, 503, etc…

Variations Of 502 Bad Gateway

This error can represent itself with a different name if you’re using a different browser. They all mean the same. Here is the list of variations you may see.

  • “502 Bad Gateway”
  • “Error 502”
  • “HTTP Error 502 – Bad Gateway”
  • “502 Service Temporarily Overloaded”
  • “502 Proxy Error”
  • A blank white screen
  • “502 Server Error: The server encountered a temporary error and could not complete your request”
  • “HTTP 502”
  • Temporary Error (502)
  • 502. That’s an error
  • 502 bad gateway Cloudflare
  • Bad Gateway: The proxy server received an invalid response from an upstream server

How to Fix a 502 Bad Gateway Error

Normally, error 502 appears due to a fault in the server, but it may happen from the client-side as well. We gonna look at the methods that can solve both client and server end problems.

Before you begin, I request you to create a backup of your site if you’ve not done it already because some solutions shown below involves risk.

I’ve arranged the solutions shown below from easy to hard. The first couple of solutions are very easy and extremely effective so do not ignore them.

Solution 1: Refresh The Page

Most of the time, the server resolves this error itself. Just wait one or two minutes, and then, refresh the page. This solution might not sound good to some people, but believe me, this is really effective.

Maybe there is no issue on your site, it’s just the server that is unable to complete the current request due to some restriction/limitation. It will resolve the error on its own.

So, wait and try again after some time.

Also, to check the current status of your website, you can go to site24x7.com, enter your domain name and click check. Site24x7.com will tell you the exact status of your website.

As you can see in the above screenshot, my site is not having any issue right now, the status is “Ok”. If it tells you that your site is currently having a 502 Bad Request Error, then follow the next solution.

Solution 2: Clear Browser Cache

Browser cache is a temporary storage area in memory or on disk that carries the most recently downloaded Web pages.

As you bounce from Web page to Web page, caching those pages in memory lets you quickly go back to a page without having to download it from the Website again.

Caching is a great way to serve a site faster to the users, however, sometimes instead of saving our time by loading a site quickly, browsers may serve us an outdated cached page.

If you haven’t cleared your browser’s cache data for a long time, then clear it right now because this may resolve the issue.

Clearing browser cache is simple. Follow the instruction given below to quickly clear the browser cache, but before you begin, I request you to download all the passwords you’ve saved in your browser.

If you don’t know how to download passwords, here is the guide for you by webnots.com

How To Clear Cache in Google Chrome
  • Open Google Chrome
  • Tap on the ︙icon from the top right corner
  • A new menu will open, click on Settings from the menu
  • Scroll down a little bit, and you’ll find Privacy and security, click Clear Browsing Data under Privacy and security
  • Select the time range as “All Time”, select both cookies and cache, and don’t check browsing history. Click on Clear Data.
  • Wait for one minute, the data will be erased
How To Clear Cache in Safari
  • Open the Safari Browser
  • Open the Safari tab from the top right of your screen and then click Preferences from the dropdown menu.
  • Now you can click on the Advanced tab of the menu that pops up.
  • Select the “Show Develop menu in menu bar” box and click close the Preferences menu.
  • Click on the Develop tab from the Safari menu visible at the top of the page.
  • Click Empty Caches from the dropdown menu and wait for some time.
How To Clear Cache in Mozilla Firefox
  • Select the menu drop-down in the right upper-hand corner to choose Preferences.
  • Go to the Privacy & Security tab and hit Clear Data under the Cookies and Site Data area.
  • Select the Cookies and Site Data option, after that click the Clear button. Close the Preferences page. Any changes you have made will automatically be saved.

Now, once you’re done with the steps shown above, go to your website or the site you wanna use and refresh it.

If the problem occurred due to caching issue, the problem will get resolved.

Solution 3: Disable Proxy

According to experts, proxy servers work as a firewall and web filter, deliver shared network connections, and cache data to speed up everyday requests.

A right proxy server keeps users and the internal network rescued from the bad stuff that lives out in the wild internet.,

Enabling this service can cause problems in accessing Internet websites because the proxy server settings have been configured.

This is rare but this error might appear if you’re using a proxy. Disabling proxy can be vital in resolving a 502 Bad Gateway error, here is how to disable proxy in Chrome.

How To Disable Proxy in Google Chrome
  • Open Chrome
  • Click on Kebab Menu (︙) available at the top right corner
  • Select “Settings”
  • Now, scroll down a bit and click “Advance”, after that under System, click Open your computer’s proxy settings. (Note: For Windows 7 and Windows 8 or 8.1 users, this will open the Internet Properties window)
  • Turn off Automatically Detect Settings under Automatic Proxy Setup
  • Turn off Use a proxy server as well
  • Make sure to click Save once you’ve changed the settings.

How To Disable Proxy in Safari Mac

  • In the Safari browser, click Safari, then Preferences…
  • Click the Advanced tab. Next to Proxies, select Change Settings…
  • Under the Proxies tab, uncheck any checked boxes.
  • Click OK > Apply.
How To Disable Proxy in Safari iPhone
  • On your iOS device, click Settings. Tap Wi-Fi.
  • Click on your current active Wi-Fi network.
  • Scroll down to HTTP PROXY. Click Configure Proxy.
  • Tap Off > Save.

Solution 4: Disable/Remove Chrome Extensions

Browser extensions are a great way to extend the functionality of your favorite browser. But bad Chrome extensions can cause much more damage than help.

Whether they utilize lots of system resources, trigger errors on your site, gather your data, install adware, divert your searches to spammy sites, or similar, you don’t want them on your pc.

Wait for one or two minutes and then refresh the site in Incognito mode. If you don’t see any errors in Incognito mode, then it shows that an extension is causing the issue.

Go to the main window of Chrome and click on the extension icon from the top right corner and then click “Manage Extensions”

Remove all the extensions you have. Check the website, if it is working then come back to the chrome extension zone, and activate extensions one by one until you find the problematic extension.

Once you find the problem causing the extension, simply remove it or replace it with a different one.

Solution 5: Try on Another Device

Test your site on another device. If you have another phone or a PC, open the website in it and check whether the site is working or not.

Also, you can restart your device or router and check the site again to make sure it’s not a device issue.

If the error is temporary, using a different device may fix the issue. So, do it right now!

Solution 6: This Might Be A DNS Issue

If you’ve recently transferred your domain to a new host, chances are that your domain is not resolving to the correct IP, or the DNS server is simply not responding.

So, wait at least 24 hours, and try again. However, it also depends on the TTL value (Time to Live Value) of your DNS records.

Now, you can also try to clear the DNS cache. The process is a little different than clearing cache in browsers, but the steps are easy. Let’s see how to clear the DNS cache.

How To Flush DNS Cache in Chrome

  • Click and press both Windows+R keys together or simply right-click the Windows Start menu and after that click Run. No, type cmd to open the command prompt console of Window. If you don’t have administrator privileges currently, then run the cmd command by pressing Ctrl+Shift+Enter together.
  • Once the command console is open type ipconfig /flushdns on the command prompt and then press enter. This command will now clear DNS cache files on your computer and reset the DNS resolver cache.
  • If everything goes well, you’ll see the confirmation message on your screen.

How To Clear Cache in Linux

Some of you might be aware that Ubuntu doesn’t cache DNS records by default.

The steps shown below are only for those who have manually installed DNS services like name service caching daemon (NSCD).

  • Click on the Ctrl+Alt+T keys together to open the terminal window.
  • Enter the below command line to flush DNS cache files on the init.d subdirectory:
sudo /etc/init.d/nscd restart

Here is how to flush the DNS cache on a system that utilizes systemd.

  • Now, click Ctrl+Alt+T keys together to open the terminal window.
  • Enter the following command line:
systemd-resolve --flush-caches
  • Type the following in the command prompt to see whether or not the previous command has successfully cleared the DNS cache.
systemd-resolve --statistics

How To Clear Cache in Mac OS X

  • Click the F4 key, enter terminal in the Launchpad’s search field to open the command terminal window.
  • If you’re currently using Mac OS SierraX El CapitanX MavericksX Mountain Lion, or X Lion, then the next step is to type the following in the command prompt:
sudo killall -HUP mDNSResponder
  • To clear DNS cache on Mac OS X Yosemite, put the command:
sudo discoveryutil udnsflushcaches
  • If you are running on Mac OS X Snow Leopard, type the below command:
sudo dscacheutil -flushcache
  • For people who are using Mac OS X Leopard and below, enter the following command to clear DNS cache:
sudo lookupd -flushcache
  • To flush DNS cache on Mac OS X High Sierra, put this line in the command prompt:
sudo killall -HUP mDNSResponder
  • Enter this command to flush DNS cache on Mac OS X Mojave:
sudo killall -HUP mDNSResponder
  • If you are running on Mac OS X Catalina, type this command:
sudo killall -HUP mDNSResponder
  • Follow this command to flush DNS cache on Mac OS X Big Sur:
sudo dscacheutil -flushcache; 
sudo killall -HUP mDNSResponder

How To Clear Cache in Google Chrome

  • Open Google Chrome and enter the following address into its search address bar:
chrome://net-internals/#dns
  • Click on Clear host cache once the page is open.

Solution 7: Disable Cloudflare Temporarily

The main reason to use Cloudflare is to increase the speed and load time of web pages. Cloudflare simply solves the annoying delay.

Especially websites such as news organizations that have millions of pics, have to face a tremendous amount of data traffic caused by images, articles, and also other media files such as gifs and videos.

Although, Cloudflare is a great tool, however, sometimes it can trigger errors, and one of them is 502 Bad Gateway.

You should try to disconnect/pause your website from Cloudflare temporarily and check whether the issue is resolved or not.

If you don’t know how to pause or disconnect your website from Cloudflare then follow the steps shown below.

Step 1: Go to Cloudflare and Login

Visit cloudflare.com, and click Login. Enter your user ID and Password.

Step 2: Select the Domain

Once you’re logged in to your Cloudflare dashboard. You’ll have to select the Domain which is having the issue.

Step 3: Click on Pause Cloudflare on Site

Scroll down a little bit, under Advanced Actions, click on Pause Cloudflare on Site.

Step 5: Click Confirm

You’ll get a pop in which Cloudflare will ask to “Confirm” the action. Click on Confirm and Cloudflare will stop working on your site.

Now, go to your website and the status.

What if you’re using a different CDN? The steps are almost similar for every CDN, if you’re unable to see the Pause option simply connect to their customer support team or check their support community, you’ll find the answer there.

Solution 8: Restart Your Server

Restarting your server may help you remove the HTTP 502 error from your website. However, the problem is, most web hosts don’t allow users to access their servers.

But, if your host is not like others or if you’re using a VPS plan, then go to your server area and restart it.

Also, check the server usage, if you see a huge spike in the server usage graph, then your site might have encountered a bot attack recently.

Go to your CDN and turn on Bot Fight Mode to protect your site from harmful bots.

Note: Restarting your server may down your site for some time.

Solution 9: Check Error_log File

The error_log file contains information about why the error occurred on your site, when the error appeared, and which page or post initiated the error at what time.

Checking your error_log file could be important in resolving this issue.

Error_log file is found in the public_html folder in cPanel. If you’re unable to find it, then click on the settings option visible at the top right corner of cPanel, and then choose “Shown Hidden File”. Reach your host, if you’re still unable to find the error_log file.

Open the error_log file, examine the latest error data generated by the error_log file.

Error log file

As you can notice in the above screenshot, the last error that appeared on my website was on 23 November 2021 at 03:16:10 UTC, it was just a notice, and it also inform me that a plugin (Wordfence) generated this issue.

After understanding what drove the issue, I can take the step accordingly. I can either remove the plugin or deactivate it.

Solution 10: Deactivate All Your Plugins

A poorly coded plugin is very dangerous for your site. It can invite many errors, however, we as a blogger sometimes ignore these plugins, which is not good at all.

If you got this 502 Bad Request error just after installing a plugin or updating a plugin, then you should deactivate it as soon as possible.

However, due to the 502 error, you won’t be able to log in to your WordPress dashboard. So, how we can deactivate it?

Well, we gonna use our Control Panel to deactivate all the plugins. Once all the plugins are deactivated, we are gonna activate every plugin one by one until we find the faulty one.

Follow the steps shown below. Again, create a backup because this involves risk.

  • Step 1: Log in to cPanel

Type yourdomain.com/cpanel to reach the cPanel login page, it’s a shortcut. If you don’t remember your ID and Password, then check the email you received after buying your hosting plan.

  • Step 2: Click on File Manager

The File Manager option is available under Files. Click on it to open it.

  • Step 3: Open Public_html Folder

The Public_html folder is one of the most crucial folders in the cPanel because it holds the most important files and information of your website. Double click on it open it.

  • Step 4: Open Wp-Content Folder

Under Public_html, there is another folder named Wp-content. This folder includes information about plugins and themes. Double-tap on it to open it.

  • Step 5: Rename Plugins Folder

Under the Wp-Content folder, you’ll see the Plugins folder.

Select Plugins folder, then right-click on it to see the Rename option, or just click on the “Rename” option visible at the top menu.

You have to rename the Plugins folder to something else like Plugins2. Once you’ve modified the name, click on “Rename” to save it.

As you can notice in the above screenshot, I’ve named the plugins folder as “plugins2”.

  • Step 6: Check Your Website

Go to your site and refresh it, if it is functioning, then it means that a plugin was causing the issue.

  • Step 7: Rename Plugins Folder Back to its Original Name

Go to cPanel again and open the Wp-Content folder. Change the name of the plugins folder to its actual name (plugins).

For example, I had renamed the plugins folder as “Plugins2”, so I’ll switch the name back to “plugins”.

Click on “Rename File” after reversing the name back to the original name (plugins).

Now, go to your WordPress dashboard plugin zone, and activate plugins one by one until you find the faulty plugin.

Solution 11: Contact Your Host

If all the solutions shown above are incapable of solving your issue, it is always better to reach out to your host.

They are experts and they see these kinds of concerns every day. Contact them especially if you’re a beginner and just starting.

You can also check their community forum, you may find solutions there as well.

HostGator – 0824 661 4102

Bluehost – 00 1 801-765-9400

Godaddy – 040 6760 7600

SiteGround – Chat Support 24/7 – Read How To Contact SiteGround Customer Support

Hostinger – Live Chat Support 24/7 – Contact Now

Kinsta – 24/7 Live Chat Support

Cloudways – +35635500106

A2Hosting – 888-546-8946

DreamHost – 24/7 Live Chat Support

I hope this post was helpful to you!

Check out more:

How To Fix “413 Entity Too Large Error” (Screenshots)

How To Fix 429 Too Many Requests Error (6 Pro Tips)

How To Fix 405 Method Not Allowed Error (10 Solutions)

400 Bad Request Error (Fixed) 7 Easy Ways

Sumit
Sumit

Sumit is a regular contributor to Hostinggrow.com. He has 6 years of experience in blogging, and he loves football, his favorite player is - Lionel Messi (GOAT), but he has no hate for Ronaldo.

Articles: 54

Leave a Reply

Your email address will not be published.