One of the worst parts about the internet is the cryptic error messages that can appear. In most cases, they provide very little information, which leads users to have no idea how to fix them. And the 502 bad gateway error is one of the most common.
Most of the time, resolving these errors is very easy. But sometimes it can get a bit complicated. Unfortunately, it doesn’t help that the same error can come in a variety of forms.
The good news is that there are solutions, and I will demonstrate them today.
What Is the 502 Bad Gateway Error?
The 502 error occurs when the web server receives a bad response from an inbound request. In fact, any error message that begins with “5” means that the problem is with the response the server is receiving, but we are just focusing on 502.
Or in other words, when you were connecting to the website something went wrong. Yes, I know that’s not very specific.
The reason for that is that there can be multiple things that go wrong.
Here are the most common causes of a 502 Bad Gateway error:
Too Much Traffic
If you’ve tried buying a Playstation 5 online, I guarantee you have seen the 502 error because the most common cause is when too many visitors access the same page at the same time.
Essentially, the traffic is overloading the server’s ability to properly respond.
A Firewall Is Preventing Access
A firewall is intended to keep your device or server safe from malicious threats, and if it recognizes a site as malicious, it can block access.
Firewalls are causing fewer 502 Bad Gateway errors nowadays, but it is still possible. Whitelisting a site you trust can resolve this.
However, sometimes the firewall is not on your end and instead due to a CDN and web host not playing nice with each other.
The Website Recently Moved (DNS)
If the website has changed servers, some domains need to make changes to the Domain Name System (DNS). This is what allows users to connect to your website and can sometimes take hours to be fully active.
In some cases, it can take over 24 hours before a website fully propagates itself after the transfer.
Corrupted Files In Your Web Browser
You’ve probably heard the term “Cache” before, but to keep it simple, this is information your web browser stores to enhance the user experience. However, if that data is not deleted after a lot of time passes, it can become corrupted and cause the 502 error.
If you have your browser set up to clear cache automatically, this likely isn’t the culprit.
The Server Is Down
Hardware will eventually stop working. If a web server decides to stop working, well, you can’t access that website anymore. Another possibility is that the server is undergoing routine maintenance.
Both scenarios can result in the same 502 error.
What Does the 502 Error Look Like?
Probably the most aggravating part about the 502 status code is that there are a ton of variations. Some websites have even taken it upon themselves to customize the error page and leave out the 502 part.
As you can imagine, this makes identifying the problem even harder.
Here are some of the messages you may encounter when experiencing this error:
- Error 502
- 502 Bad Gateway
- 502 Service Temporarily Overloaded
- HTTP Error 502 Bad Gateway
- 502 Proxy Error
- No Message (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
And that’s just some of the error messages you may encounter! It gets a lot more complicated when website owners customize the message. Although to be fair, some of these custom messages are much more helpful.
For example, you might have seen the “Twitter Is Over Capacity” error screen (where the whale is being lifted by the Twitter birds). If you recall, one of the reasons the error occurs is due to server congestion, or too much traffic.
This message is much clearer than what was just listed above. However, it’s not always better.
For instance, Google uses the default “502. That’s An Error.” message which looks nice but doesn’t really tell the user anything.
How to Fix the Bad Gateway Error
Now that you know what the error is and how to identify it, let’s talk about solutions. The good and bad news is that there are a lot of ways to resolve this error.
None of them are particularly difficult, and in some cases, the problem might not be on your end.
1. Reload the Page
This one might make your eyes roll, but it is by far the most consistent way to resolve this error. When you reload the pages, you are actually sending the server another request. Thus even if the first one failed, this one may succeed.
However, odds are, you have already tried reloading the page to no avail. If the core problem is congestion (too many people at once) then this might actually make the situation worse as you are just adding to the users trying to access the page.
However, sometimes the simplest solution is the most effective.
2. Load the Page On Another Web Browser
The cache stored regarding your website can sometimes cause this error. To determine that is the case without clearing your cache, all you need to do is try accessing the website on another browser.
If you are still encountering the error, it is not related to the cache.
However, if the error is resolved, then go back to the previous web browser and clear the cache to resolve the error.
3. Check the Status of Web Servers
All web servers undergo maintenance, and in most cases, the website owners are alerted to it from their web hosting companies before it happens. In many cases, those websites will let visitors know the website may be down via social media.
If this is the case, there’s nothing you can do but pass some time and try again after the maintenance is over.
It is also worth contacting your web hosting company to have them verify your web server. Sometimes the web server may be down without them notifying you, which can cause you a lot of headaches trying to resolve an error out of your control.
4. Flush Your DNS
If this is your own website and you have recently migrated to a new server, then the cause is likely a DNS error. This will take time to resolve, but one way to speed it up is to clear your local DNS cache, which is essentially the same as clearing browser cache.
Note: The method to flush local DNS is different on Windows and Mac.
On Windows, open up a command prompt and enter “ipconfig /flushdns” and within a few seconds you should see a success message that reads “Successfully flushed the DNS resolver Cache.”
For Mac users, paste the following line into the terminal “dscacheutil -flushcache“. However, unlike Windows, there is no success message.
5. Change the DNS
The DNS server is an essential part of how you connect to the internet. DNS issues can increase gateway issues, but changing the DNS servers is relatively easy.
The ISP (internet service providers) sets the DNS server settings. But users can set them to third-party DNS settings and resolve those issues.
Options like OpenDNS or Google DNS are good choices. Changing the DNS server increases the website speed and reliability for ranking.
6. Check Your Firewall
If you use a CDN like Cloudflare, there are actually two firewalls that can cause a problem, and you do not have control over either one. The first would be the CDN’s firewall, and the second would be the web host.
The good news is that these error messages can be a bit clearer.
In many cases, the massage will show you where the connection problem is occurring. Then, you need to contact the necessary party to resolve it.
Granted, sometimes they may try to point the finger at each other, but alerting each party is usually enough to resolve it.
7. Check Your Plugin & Theme (WordPress Only)
WordPress is a terrific platform, but sometimes not every plugin and theme is coded well. And sometimes as a result of bad code, your website can produce 502 errors in an inconsistent manner.
The first step is to determine what is causing it.
One way to do this is to disable all of your plugins and see if the error persists. If it does not, then you need to determine which plugin is the culprit. At this point, you want to activate each plugin one at a time and check for the error.
If it is not a plugin, then be sure to check your theme. Obviously changing your theme is not ideal, but it is necessary to determine if it is causing an error. Cloning your website onto a subdomain to test this is a smart choice.
8. Check the Error Log
Most web hosting companies offer you an error log in one form or another. These just list the errors your website experiences, but unlike the 502 Bad Gateway error, these are easier to pinpoint the cause.
How you access them changes depending on your web host.
9. Try Using or Disabling a VPN
Sometimes using a VPN can either cause or solve the problem. In either case, if you are using a VPN, try disabling it. If not, consider trying a VPN to see if the error is resolved. This means something is wrong when the request is being sent from your device.
The good news is that if you don’t have a VPN, many offer free trials you can try to see if it works.
10. Clear Cookies and Cache
Solving the browser gateway error indicates problems with cache build-up. Corrupt files in the cache could stop the internet browsers from accessing the targeted website.
If you face a gateway error because of a bad cache, you need to remove it. Users need to access the browsing history tab through options and follow these steps:
- Access the internet browser’s options by clicking on the options tray.
- Select the History option located and click on it
- Clear browsing history by choosing the option available
- Choose the “All Time” option located if you are using chrome
- Mark the cookies and cache removal as well
- Wait for the internet browser to remove all your history, cache, and cookies.
Note: Reloading the websites with a clear cache can reduce the website loading speed.
11. Restart the Device
Temporary issues with the internet router or the computer system can also trigger the gateway warning. Additionally, there’s a chance that some systems might face problems because of WordPress themes.
It’s best to remove the ones you might have installed on your system and see if that solves the problem. We also suggest checking if the problem is on the user’s end.
Identifying these problems by restarting the internet router or the computer system can help. It makes it easier to check for possible problems caused on the user’s end after removing plugins.
What If None of These Solutions Work?
In the unlikely event that none of these solve your issue, and assuming that your server is not down, the only option left is to double-check everything and let some time pass.
Many web hosting support teams can help you troubleshoot this error if the problem persists.
If the problem stems from too much traffic, there is not much you can do but wait, or upgrade your servers to accommodate larger crowds.
Does A 502 Bad Gateway Error Impact SEO Rankings?
If the 502 error persists for several hours, it can result in lower rankings on search engines. However, if your website has just gone down due to this error, a search bot will still crawl your website like normal using a cache.
Imagine a website gets ranked and crawled consistently during its downtime. The server will probably crawl from the cache, not giving the browser a chance to re-crawl the pages. It doesn’t matter if your site is down for a few minutes.
The bot may return after a set period of time to ensure the error is gone. At this point, if the error is not resolved, your rankings will be impacted.
Thus, you need to ensure this error does not occur regularly.
Don’t Let Error Messages Frighten You
Error messages are common on the internet for both visitors and website owners. No website will ever be error-free, and that’s fine. What is important is how fast you respond to an error and attempt to solve it.
In reality, only errors that exist for a prolonged period of time will have an impact on your rankings, so don’t panic.
Which solution worked for you? Did you take any steps to prevent it from happening in the future?