A 502 Bad Gateway error indicates that the server your computer or smartphone was trying to connect to received an invalid response from a higher-level server.Error 502 Bad Gateway occurs when the proxy server, DNS server, and most often the server that hosts the site is not working properly. The problem can spread both to the entire resource and to individual pages. It depends on the nature of the problem. There are varieties of 502 errors: Bad Gateway Nginx, Bad Gateway Apache.
Causes of the 502 Bad Gateway Error
The first and main reason is server overload . Overloading can be caused by several problems:
- A large number of visitors at the same time . A web resource can be visited by a limited number of visitors. How many people can visit the site depends on the capabilities of the server (the size of the RAM) and the settings that the creator of the resource has made. If for some reason more users visit the site than planned, the service may not be able to cope and the page will return a 502 code. This happens with promotions and sales in online stores.
- Attack by hackers or DDoS attack . This issue is related to the previous overload cause. The hacker imitates a large influx of users, causing the server to fail. Such attacks can be used to reduce sales.
- Poor site optimization . The resource settings are made in such a way that a small number of visitors generates many requests. In this case, you need to optimize the server's work with user requests.
- The second reason for the occurrence of code 502 may be PHP errors . If incorrectly configured plugins were added to the control panel to expand the functionality of the site, they may cause problems in their work. Together with them, the entire site will show the error. Also, if the site code is written incorrectly, requests can give a negative result.
- Browser error . The problem may be on the user's side if he has extensions installed that break the connection to the site server.
How to fix error 502?
- Reload the page if the problem was caused by the influx of visitors. Perhaps after a while, visitors will leave the page and you will be able to see the content.
- Try visiting another web resource . If you can go to another site, then the problem is on the side of the resource owner and there is nothing you can do. Return to the page later when the administrator restores access.
- Check your internet connection . Due to slow or unstable connection, the browser may not receive data from the server.
- Launch your browser in incognito mode . In Incognito mode, the browser works with basic settings. If you managed to access the web resource in this mode, then one of your browser extensions is interfering with the connection. This extension needs to be disabled.
- Clear your cookies . If you still see a 502 error when you re-enter the site, clear your browser cache . Perhaps access has already been restored, but your browser is accessing the old version of the page from the cache.
- Clear the DNS cache . The DNS cache is a temporary database on your computer that keeps a record of all recent visits and attempts to visit websites and their IP addresses. The cache allows you to speed up access to frequently visited web resources. If the site has changed DNS, and the data from the cache is sent to the old IP address, a 502 code will appear in the browser. After clearing, the browser will start accessing the new IP address.