Error 502 bad gateway is a very common and popular error message seen on various websites from time to time. It can be very confusing as to why the website is going through such an error, which worked perfectly fine a couple of days ago. You may try to restart the browser, refresh the website – even clear the cache and still have no luck in properly accessing the concerned website. Turns out that 502 errors generally arise due to server-related issues, which the user has minimum to no control over. In this article, we take a look at what exactly is 502 bad gateway and how to fix it.
What is a 502 Bad Gateway error?
A 502 Bad Gateway error is an HTTPS status code shown on a website when the browser receives an invalid response from the website’s server. This invalid response may be caused due to an unknown issue within the webserver or hosting and when that happens, an error 502 is a way of depicting such errors.
How to fix 502 Bad Gateway error
Whether you’re a website owner or a visitor, to figure out a fix for 502 bad gateway errors, you can go through various troubleshooting methods and hopefully get rid of the issue.
Reload the page
One of the simplest ways to fix an error 502 is by reloading the website. Sometimes, such an error may be caused by a sudden rise in traffic which prevents more users from accessing the website at that particular time. If the issue persists even after refreshing, then go for other troubleshooting steps.
Surfing a website in incognito or private tab temporarily disables the browser’s extensions and plugins, which might be interfering with the website’s server and leading to a 502 bad gateway error.
Clear browser cache
It may happen that the browser you’re using is presenting a cached version of the website or URL you’re trying to visit. In such cases, you can go ahead and try clearing the browser’s cache and be presented with the latest version of the website, once refreshed.
Contact hosting provider
If you’re a website owner and are facing error 502 on all or particular URLs, try contacting the hosting provider for assistance. It might be possible other website’s on the same hosting might be facing such errors, or if the issue is at your end only, the technicians may dig up the root cause and even fix it for you. Whatever the case may be, contacting your hosting provider can be considered the first mode of contact for website owners.
A website may also show a 502 bad gateway error when the server is down and is going through unnotified maintenance. In such cases, the only solution is to wait till your hosting and web servers are once again up and running.
Check Your Plugins and extensions
Make sure the plugins and extensions installed on your website are running the latest versions. This is because at times buggy and unstable plugins can interfere with the website’s functioning and lead to errors such as 502 bad gateway. The same goes for the extensions installed in your browser which access the websites you browse through.
Restart Your Devices
If you’re facing the error 502 bad gateway on a single device and have tried several troubleshooting steps such as clearing cache, and refreshing the website then go ahead and give your device a restart.
Temporarily Disable CDN or Firewall
CDN or content delivery networks act as an intermediary between the website server and browser which helps in loading the content such as text, images, videos etc. faster within a website. When CDNs such as Cloudfare face outages, it may cause issues like 502 errors on many websites. When that happens you can either wait for the CDNs to be back up or temporarily disable them so that the content isn’t routed through them and is delivered directly to the user.
Check Error Log
As the name suggests, an error log is a file that stores all the recently occurred errors on the website’s servers. Once you manage to open the file, you can easily check the culprit causing the error 502. On WordPress websites, the error log can be accessed by adding the following few lines into ‘wp-config.php’ within Cpanel.
define( ‘WP_DEBUG’, true );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
All the errors generated will appear in the ‘wp-contents/debug.log’ file and accordingly, you can take action to fix them.
What causes 502 Bad Gateway error?
Error 502 bad gateway is generally caused due to issues related to the network or server but the problem may arise from the user’s end as well. Here are several ways you may see error 502:
Users may face 502 errors on a website when the server is overloaded with traffic and runs out of resources to accumulate such a volume. When that happens, the browser is not able to communicate with the server and thus a 502 error as it receives an invalid response.
Sometimes there might be certain faults with the user’s browser which is triggering 502 errors. There can be several culprits leading to such errors like defective browser extensions and ad-blockers which are interfering in getting a proper response from the server of a website you’re trying to visit. Also, updating browsers to their latest versions and clearing cache improves the performance and stability from time to time.
If you’ve just launched a new website, it may be possible the Domain Name System (DNS) is not redirecting to the correct IPs yet. This takes around 24 hours to settle in and once that happens, errors such as 502 bad gateway should be gone. Furthermore, at times the DNS servers might be unresponsive as well which breaks the connection between a website and server, thus triggering 502 or similar errors.
Firewalls protect you from malicious or unnecessary traffic coming from shady sources. However, firewalls may have a certain flaw that blocks genuine websites, making them inaccessible to the end-user.
502 Bad Gateway error variants
Different websites may have different ways of showing a 502 bad gateway error but the root cause of such an error may remain the same i.e. an invalid response from the server-side. Here are different variations of HTTPS status code 502 bad gateway you may come across:
- 502 Proxy Error
- Bad 502 Gateway
- 502 Error
- Error 502
- HTTP Error 502 Bad Gateway
- Temporary Error (502)
- 502 Server Error: The server encountered a temporary error and could not complete your request
- 502 – Web server received an invalid response while acting as a gateway or proxy server