With active surfing in the network, everything does not always go smoothly. From time to time, users instead of a site page encounter HTTP errors. If, as an Internet user, you encounter an error 500, in most cases the problem is not with you or your Internet connection, but with the site server. The exception is error 502, which may indicate incorrect settings, especially if the window with an error appears very often and no matter which site you are trying to go to. First you need to determine that the methods for solving the 502 Bad Gateway error for the user and the site administrator are different. Consider the causes and solutions in more detail.
Troubleshoot 502 Bad Gateway.
502 Bad Gateway - what does it mean
The HTTP Internet protocol in response to each request provides a status code. The most common of them is 200: OK, everything works as it should. Usually this status is not displayed. Instead, visitors see site content. Different errors have different reasons: if errors 400 mean that problems are with the user, then codes from 500 to 511 mean that a negative answer 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 accessed through the main server could not 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 sent through gateways. That is why the emergence of an error window can cause some inconvenience - it is not entirely clear at what point in the process the request has detected a malfunction.
Sources of error 502 Bad Gateway
In most cases, an invalid gateway error occurs on the server side, so a simple user cannot fix it. It is also possible that the browser used registered a 502 Bad Gateway error, which does not actually exist, or you are simply disconnected from the network. The source of the error can also be the following:
- Server failure - the gateway from the target server receives a negative result. This may occur due to a system failure. In rare cases, servers can be disconnected from the network, for example, 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 may be an unexpectedly high interest in the site or even a DDoS attack. This means that the attacker uses a virtual network to overload the server and trigger a system crash.
- Incorrect PHP programming - sometimes the problem is in the site code. Then some requests will receive a negative result.
- Communication Error — Firewalls (server and client) can cause errors when forwarding requests on both sides of the connection.
- Browser Error - cause a web site display error and 502 Bad Gateway may extend your browser.
There are 3 main causes of the 502 Bad Gateway error:
- Domain name not allowed - domain name by IP address is not allowed. It is important to note that DNS changes can take as much time as they are active. It depends on the TTL or “lifetime” set aside for each record.
- Source server is unavailable - Internet connection is not working or not.
- The firewall blocks the request — the firewall blocks the connection between the edge servers and the source servers on the site. It may also be caused by CMS security plugins. Some DDOS security systems are too active, therefore blocking requests from content delivery servers.
How To Fix Error 502 Bad Gateway
To correct error 502 Bad Gateway, consider the solution to the problem from the point of view of the site administrator. A visitor to your portal has shared with you information that he sees error message 502 when trying to access your site. What does this mean for you? The administrator is also not always able to correctly determine the cause of the error. First, you need to check whether the site is available as a whole. If your server really fails, you should contact your hosting provider. They may already know about the error, and their support is already working on recovery. You should also check the server log files for error messages. In particular, PHP programming often becomes a source of errors, so be sure to check if the source of errors is in the code or in the database. If necessary, you can use the old backup to quickly fix the error.
Often the error occurs only because the server was temporarily overloaded or could not respond to a higher request for too long. If such overloads begin to occur more often, you should contact your hosting provider. Together, you can achieve a better configuration of the web server, but this is not always possible. Then you need to check if your firewall is configured correctly and make sure that it does not block any legitimate requests. Another source of error may be a name resolution malfunction. Check your DNS settings with your hosting provider. Most often, 502 after some time disappears by itself. When an error occurs outside of your sphere of influence, it is solved by an Internet Service Provider (ISP) or a web server hosting provider without any intervention on your part. If the fault arises due to your fault, you need to determine its source and method of elimination as soon as possible.
Temporarily disable your content delivery network (CDN)
Browser requests are sometimes forwarded through a reverse proxy server. In other words, using a proxy server creates an intermediary between the user's browser and the site 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 web site server can create problems. When this happens, your visitors (and you) may encounter error 502. Checking and finding out if your CDN is causing this problem is quite simple. All you have to do is temporarily disable the service and then check if the site loads correctly without it. The process of disabling CDN depends on the service you are using.
Now when you try to access a website, its source server will respond to the request without intermediaries. If error 502 disappeared, your CDN was probably the source of the problem. In most cases, you just need to wait a few hours before turning the service back on. Of course, be sure to check and make sure that the error no longer occurs. If you use another CDN, you need to review its documentation for instructions on how to temporarily disable the service.
Clear browser cache
If the problem is really server-side, but you need to access the content of the site, there are ways to get around the problem. One of them is the browser cache. Modern browsers for some time keep copies of websites on their own servers, so they can display an earlier version of them. To load a page from the Google cache, type cache: in the search box and then the URL you want to visit (for example, cache: //facebook.com). However, you need to remember that you are viewing an outdated version of the site. To get rid of the error, clean your browser's cache.
Delete your browser cookies
What to do with error 502? In most cases, you can fix it by simply reloading the page. If the problem is solved, then the server was just temporarily overloaded. Since such crashes can last quite long, reloading the page can help in about 15 minutes. If the error message persists, clear the cache and cookies. It may be that the browser actually just accessed data from the device’s internal memory. It is not necessary to delete all cookies - in the browser settings you can open and delete only those that are related to the corresponding website.
Start the browser in incognito mode
The error may be on your system, even if the status code points to something else. If every time you try to visit any sites, Bad Gateway pops up, most likely the error is related to your computer, browser or firewall. First, check the browser functionality. The first step is to restart it in incognito mode. If this does not work as it should, start the browser in safe mode. If the error disappears, then the problem was one of the add-ons or browser extensions that are disabled in safe mode. To do this, open the command line and enter here the full path of the browser location in quotes. Each browser developer has different commands to start 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.
Fix the DNS server
Error 502 may occur due to incorrect binding of the domain name and IP address. This is due to the migration of the website to a new host, which usually takes some time. The solution is to clear the DNS cache on the local system just 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 "The DNS cache has been cleared successfully."
Logs are records of all actions you have performed 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
A content delivery network (CDN) is a third-party service for rendering “heavy content, ” which includes large images and video. CDN is used by the application to maintain effectiveness. Firewall configuration may allow invalid or malicious content to pass through the gateway, resulting in a 502 Bad Gateway error. To solve this problem, you just need to disable the CDN.
Try using a different browser.
Try to connect through another browser. If the opening of the page passes without failures, then the current standard browser must be removed and reinstalled. If switching browsers does not solve the problem with an incorrect gateway error, you need to check your network settings. The easiest option is to reboot the 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 for this is a false record on their DNS server. To bypass the error message, enter a different DNS server in the settings. In Windows, this can be done in the TCP / IP connection settings. As a test, you can access the free Google DNS server - 188.8.131.52 and 184.108.40.206.
Contact your ISP
If the error is not caused by the provider, it remains only to wait until it disappears on its own (or use cached versions of the pages). In most cases, the error is temporary and eliminated by the administrator as soon as possible.