How to fix the 502 Bad Gateway error

DNS server address change

With active surfing on the net, everything does not always go smoothly. From time to time, users will encounter HTTP errors instead of a site page. If, as an Internet user, you encounter a 500 error, then in most cases the problem is not with you or your Internet connection, but with the site server. An exception is error 502, which can indicate incorrect settings, especially if the error window appears very often and no matter which site you are trying to navigate to. First, you need to determine that the methods for resolving the 502 Bad Gateway error for the user and the site administrator are different. Let’s consider the reasons and solutions in more detail.

Error 502 Bad Gateway on the computer

Contents

502 Bad Gateway – what does it mean

The Internet Protocol HTTP provides a status code for each request. The most common one is 200: OK, everything is working as it should. Usually this status is not displayed. Instead, visitors see the site’s content. Different errors have different causes: if 400 errors mean that the user has problems, then codes from 500 to 511 mean that a negative response is the result of a server error. The numbers also indicate where the error occurred – at least for users who know what the individual codes mean.

Error 502 is usually followed by the phrase Bad Gateway, Bad Gateway Nginx, Bad Gateway Apache, or Bad Gateway: Registered endpoint failed to handle the request. This error of the wrong gateway, together with the error “400: Page not found”, is one of the most common when working on the Internet. It appears when the site being accessed through the main server was unable to forward the request. In this case, the first server functions only as a proxy or gateway. Although it can be said that all requests on the Internet are also forwarded through gateways. That is why the appearance of a window with an error can cause some inconvenience – it is not entirely clear at what point in the process the request detected a malfunction.

502 Bad Gateway error window

Sources of the 502 Bad Gateway error

In most cases, an invalid gateway error occurs on the server side, so a simple user cannot fix it. There is also the possibility that the browser you are using has logged a 502 Bad Gateway error, which does not actually exist, or that you are simply disconnected from the network. The following can also be the source of the error:

  • Server Failure – The gateway from the target server receives a negative result. This could be due to a system crash. On rare occasions, servers may go offline, such as when content violates the law.
  • Web server overload – If the web server reaches its limit, it can no longer respond to requests. Therefore, the gateway issues 502 Bad Gateway. The reason could be an unexpectedly high interest in the site or even a DDoS attack. This means that an attacker is using the virtual network to overload the server and cause a system failure.
  • Incorrect PHP programming – sometimes the problem is in the site code. Then some queries will receive a negative result.
  • Communication error – Firewalls (server and client) can cause errors when forwarding requests on both sides of the communication.
  • Browser Error – Your browser extensions can cause a website display error and 502 Bad Gateway.
DDoS Attack Principle

DoS attack scheme

Causes of occurrence

There are 3 main reasons for the 502 Bad Gateway error:

  • Domain name not resolved – Domain name by IP address is not resolved. It is important to note that DNS changes can take as long as they are active. It depends on the TTL or “time to live” allotted for each record.
  • Source Server Unavailable – Internet connection is down or no Internet connection.
  • Firewall Blocking Request – The firewall is blocking communication between the Edge and origin servers in the site. May also be caused by CMS security plugins. Some DDOS protections are too active, so they block requests from content delivery servers.

How to fix the 502 Bad Gateway error

To fix the 502 Bad Gateway error, let’s look at the solution from the site administrator’s point of view. A visitor to your portal has shared with you that when he tries to access your site he sees a 502 error message. What does this mean for you? The administrator is also far from always able to correctly identify the cause of the error. First, you need to check if the site as a whole is accessible. If your server does crash, you should contact your hosting provider. They may already be aware of the error and their support is already working on a recovery. You should also check the server log files for error messages. In particular, PHP programming is a common source of bugs, so be sure to check if the bug is in your code or in the database.If necessary, you can use an old backup to quickly fix the error.

Uploading backup files

Often, the error occurs only because the server was temporarily overloaded or was too long to respond to an upstream request. If such overloads begin to occur more and more often, you should contact your hosting provider. Together, you can achieve a better web server configuration, but this is not always possible. Next, you should check if your firewall is configured correctly and make sure it is not blocking any legitimate requests. Another source of error could be a malfunctioning name resolution. Check your DNS settings with your hosting provider. More often than not, 502 will disappear on its own over time. When an error occurs outside of your sphere of influence, it is resolved by the Internet Service Provider (ISP) or web server hosting provider without any intervention on your part. If the malfunction occurs through your fault,determine its source and method of elimination as soon as possible.

Temporarily disable your content delivery network (CDN)

Browser requests are sometimes redirected through a reverse proxy server. In other words, using a proxy server creates an intermediary between the user’s browser and the site’s server. Some services, such as Content Delivery Networks (CDNs), use reverse proxy technology to route incoming traffic as efficiently as possible. But sometimes this extra layer when trying to connect to the original website server can create problems. When this happens, your visitors (and you) may encounter a 502 error. It is easy enough to check and find out if your CDN is causing this problem. All you need to do is temporarily disable the service and then check if the site loads correctly without it. The process for disabling a CDN depends on the service you are using.

Disable CDN on the site

Now, when you try to access the website, its origin server will respond to the request without intermediaries. If error 502 is gone, it is likely your CDN was the source of the problem. In most cases, you just need to wait a few hours before re-enabling the service. Of course, be sure to check and make sure the error no longer occurs. If you are using a different CDN, you need to view its documentation for instructions on how to temporarily disable the service.

Clear your browser cache

If the problem is indeed server-side, but you need to access the content of the site, there are workarounds. One of them is the browser cache. Modern browsers keep copies of websites on their own servers for a while, so they can display an earlier version. To load a page from Google cache, enter cache: in the search box followed by the URL you want to visit (for example, cache: https: //facebook.com). However, remember that you are viewing an outdated version of the site. To get rid of the error, clear your browser cache.

Clearing the cache in Mozilla Firefox

Delete your browser cookies

What to do with the 502 error? In most cases, it can be fixed by simply reloading the page. If the problem is resolved, then the server was simply temporarily overloaded. Since these glitches can take quite a long time, reloading the page can help in about 15 minutes. If the error message persists, clear your cache and cookies. It could be that the browser actually just accessed data from the device’s internal memory. It is not necessary to delete all cookies – in your browser settings, you can open and delete only those that are relevant to the respective website.

Clearing cookies in Google Chrome

Run your browser in incognito mode

The error could be on your system, even if the status code indicates something else. If every time you try to visit any site, Bad Gateway pops up, most likely the error is related to your computer, browser or firewall. First, check the functionality of your browser. The first step is to restart it in incognito mode. If that doesn’t work as expected, start your browser in Safe Mode. If the error goes away, then the problem was with one of the browser add-ons or extensions that are disabled in Safe Mode. To do this, you need to open a command line and enter the full path of the browser location in quotes here. Each browser developer has different commands for starting Safe Mode:

  • Firefox: “C: Program Files Mozilla Firefox firefox.exe” -safe-mode
  • Internet Explorer: “C: Program Files Internet Explorer iexplore.exe” –extoff
  • Chrome: Google browser does not offer Safe Mode. Instead, just run in incognito mode.

Incognito mode in Google Chrome

Fix your DNS server

The 502 error can occur due to incorrect binding of the domain name and IP address. This is due to website migration to a new host, which usually takes a while. The solution is to clear the DNS cache on the local system in the same way as you delete the cache from the browser. Open a command prompt and run the command:

ipconfig / flushdns

If the DNS cache is cleared successfully, the program will display the message “DNS cache cleared successfully.”

Ipconfig / flushdns command

Check logs

Logs are records of all actions performed by you in any application. You can check the application logs and the corresponding log on the server. Application logs will tell you which pages were requested during the execution of the application, while the log on the server will contain information about the hardware responsible for running the application and the status of all devices connected to the server.

Disable CDN plugin

Content Delivery Network (CDN) is a third-party rendering service for “heavy content” that includes large images and videos. The CDN is used by the application to maintain efficiency. The firewall configuration can allow inappropriate or malicious content to pass through the gateway, resulting in a 502 Bad Gateway error. To fix this problem, you just need to disable the CDN.

Try using a different browser

Try connecting with a different browser. If the page opens without failures, then the current standard browser must be uninstalled and reinstalled. If switching browsers does not solve the problem with the wrong gateway error, you need to check your network settings. The easiest option is to reboot your modem and router. If that doesn’t work, try switching from Wi-Fi to LAN and using a cable connection.

Restart your computer and network equipment

Sometimes the 502 Bad Gateway is caused by the ISP. The reason here is a false entry on their DNS server. To work around the error message, enter a different DNS server in the settings. On Windows, this can be done in the TCP / IP connection settings. As a test, you can access Google’s free DNS server – 8.8.8.8 and 8.8.4.4.

Go to properties of the active adapter

IP version 4 properties

DNS server address change

Check with your ISP

If the error is not caused by the provider, you just have to wait until it disappears by itself (or use cached versions of the pages). In most cases, the error is temporary in nature and is eliminated by the administrator as soon as possible.

Leave a Reply

Your email address will not be published. Required fields are marked *