Have you ever gotten a 502 Bad Gateway Error while trying to visit a website? This error tends to occur when your web server is receiving an invalid response from another. Solving the issue can be a bit of a mystery because the error doesn’t give you a clue about what is causing the error message. In this article, I will be explaining what the 502 Bad Gateway Error is, the cause of the error and how you can fix it.
What is a 502 Bad Gateway Error?
A 502 Bad Gateway Error indicates that the web server you are connected to is receiving an invalid response from another server. The error occurs when accessing an invalid server’s URL with your browser, this invalid connection returns with an HTTP 502 status code to indicate the error.
There are five HTTP status codes used for server responses. They include:
- 1xx – informational
- 2xx – success
- 3xx – redirection
- 4xx – client error
- 5xx – server error
There are several causes for the 502 Bad Gateway Error. They include issues from overloaded servers to issues with the network connection between the two servers. It could also be caused by the wrong configuration of the firewall thereby preventing access to the server. The reasons vary, but there are also various ways you can easily fix the error.
Causes of 502 Bad Gateway Error
Before you go about trying to fix the error, you should first figure out the cause of the 502 Bad Gateway Error. This way you will be able to avoid it in the future. Below are some factors that will result in you getting this error message:
- Overloaded server
One of the causes of the 502 Bad Gateway Error is an overloaded server. When the web server is overloaded leaving no space for new data resulting in its crashes. This will trigger an HTTP 502 error. a common cause of server overload includes low memory, a sudden surge in site traffic, and software timeouts.
- Browser errors
Sometimes the 502 error may be caused by your web browser. You might get this error message if you are using an outdated version of your browser, or if a faulty browser extension interferes with your browser’s connection to the web server.
- Unresolved domain name
This occurs if after changing your site’s domain name to a new host, your DNS changes have not yet been fully propagated and active. This is a temporary problem, and you will have to wait for 24 hours before the error message clears.
- Wrong configuration of firewall
Firewall blocks suspicious traffic from getting into your website. The issue comes when your website’s firewall is not properly configured, so it sees every connection as malicious and thereby blocking their access. This will trigger the 502 Bad Gateway Error as your firewall prevents other servers from accessing yours.
How to Fix 502 Bad Gateway Error
- Refresh the page
The 502 Bad Gateway Error message can be very frustrating but you never know a simple refresh of the web page might do the trick. So before going deeper and trying other fixes simply refresh the page, and wait for it to reload.
If you are still getting the error message then you can move on to the next fix. If the page doesn’t show any error after the reload, then the issue was probably caused by the network connection.
On Windows, you can simply refresh your browser with CTRL + F5 or F5, and CMD + R on Mac.
- Clear Browser Cache
If the page still shows the error, then it’s probably there are some outdated or corrupted files in your browser cache that needs clearing out. In that case, clear your browser cache and reload the page again.
Note: clearing your browser cache may result in you losing important browser data such as bookmarks and browser settings. If you don’t want that, you can export your browser data and import it back when done.
- Try Incognito Mode
To figure out if the reason for the error message is because of your browser, you can switch your browser to Incognito mode and visit the site again. To switch to the Incognito window, click on the three vertical dots at the top right corner of the browser screen and select New Incognito Window.
If the problem doesn’t show up in the Incognito mode, then there’s a possibility that an extension in your browser is the cause of the error.
Disable all the add-ons and extensions in your browser gradually until you figure out which one is the cause of the error. Once you find the faulty extension, delete it and go back to the website.
If this doesn’t help, you can switch to another browser to check if you will encounter a similar issue there as well.
- Test on Another Device
You can run the site on another device if the problem still persists on your device. This way you will be able to check if the site is down for other people as well. You can also check if the is an issue with your network connection. Using tools like downforeveryoneorjustme.com and isitdownrightnow.com you can check the URL.
- Restart Your Device
If after checking the URL with the site checking tools and you figure out the problem is from your end, you can restart your device, and disconnect your network connection (router, Wi-Fi, modem, etc). Reconnect your network and go back to the website after waiting for a moment. This should fix the issue.
- Check your DNS servers
Check your DNS server for any recent changes. If you had recently changed your website to a new host server, then the problem is probably from there.
You will have to wait for at least 24 hours before the change on the DNS server takes full effect. And until that change is in full effect, your website will still come up with the error message.
- Check Plugins and Themes
Another reason why you are getting the 502 Bad Gateway Error may be due to faulty plugins and themes installed on your website.
These poorly coded plugins and themes may be running on scripts that conflict with those on your site resulting in you getting this error message.
Mostly the cause of this error is usually caching or security plugins, so you should check out these plugins and delete the one that is causing the conflict triggering this error.
- Contact Customer Support
If you try everything and you can’t seem to fix the 502 error, contact your hosting company’s customer support and report the issue to them.
You should also outline all the troubleshooting you have done as you attempted to fix the issue, this way they will be able to support you well with what steps to take next.