Each time a site is opened, the browser sends various requests to other web servers. The servers then handle these requests and send an HTTP status code along with the required resources. Typically, HTTP status codes are not displayed unless a problem occurs along the way. Here’s how the servers inform each other and inform the end user about what went wrong.
502 bad gateway is one of the HTTP status codes that can be received by surfing the internet. Although it is not as frequent as the error 500 internal server error or error 503 service unavailable , it can still cause a headache. This tutorial focuses on the possible causes and corrections of the 502 Bad Gateway error on WordPress sites.
What does the 502 Bad Gateway error mean?
HTTP status codes that begin with the digit “5” refer to errors that occur in the event of incorrect communication between multiple servers. Although the exact reason for their appearance is generic, in most cases the cause is server side.
Obtaining an HTTP 502 bad gateway error means that the source server sent an invalid response to another server acting as a gateway or proxy. Since all requests on the web are forwarded through multiple gateways, it can be rather complicated to identify the exact point or process that caused the problem. However, there are general troubleshooting steps that you can follow to solve it.
The 502 bad gateway error can occur in various forms. Here are some alternatives you can meet:
- Temporary Error (502)
- Error 502
- HTTP Error 502 Bad Gateway
- 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
- HTTP 502
- 502 Service Temporarily Overloaded
- 502 Bad Gateway Nginx
How to fix the 502 Bad Gateway error?
- As we have said the HTTP error 502 bad gateway usually refers to problems on the server side but sometimes it can also be caused by incorrect configurations or problems on the client side. Below we will illustrate the common steps for solving problems taking into account both causes. Although some solutions are focused on WordPress, most of them can be applied to any website. Without further ado, let’s see the steps to correct the 502 Bad Gateway error.
Refresh the page
- The first solution is quite simple. Wait a minute or two and refresh the page you are on. In many cases, the HTTP 502 error is temporary and a simple page update may solve the problem. In the meantime, you can check if the website is offline using an online tool .
Clear the browser cache
- If the error persists, it may be caused by a certain cached item. Therefore, clearing the browser cache is a good approach to resolving the 502 bad gateway error.
Try another browser or incognito mode
- Even checking the connection using a different browser or different incognito mode is a great idea. It will allow you to exclude the option that the error has appeared due to a browser problem.
Empty the DNS
- The 502 bad gateway error may also appear due to DNS problems, such as cached IP address values incorrectly. In these cases, emptying the DNS is another solution you can try. Here is a tutorial on how to empty DNS on Windows, Mac and Linux.
- You can also try temporarily changing your default DNS server in Google Public DNS .
Head on another device
- If none of the above solutions solved the 502 bad gateway error, you can verify the connection on another computer or mobile device, preferably connected to a different network. This is the last step that will exclude if the error is related to your machine or if the problem is elsewhere.
Check the error log
- If the HTTP 502 error is displayed after a certain change or update, it is possible that the error is found on the website itself. The best approach is to check the error log for suggestions.
- In WordPress, you can enable error logging ( debug mode ) by adding the following lines to the wp-config.php file :
- define (‘WP_DEBUG’, true);
- define (‘WP_DEBUG_LOG’, true);
- define (‘WP_DEBUG_DISPLAY’, false);
7. Check the plugins
- It is also important to check plugins and extensions. Problems with caching plugins can often lead to the appearance of 502 bad gateway errors. A simple way to check if the plugins generate errors is by disabling them all for a short time. To do this, go to the wp-content directory and rename the plugin directory.
Check the CDN
- Another cause of the HTTP 502 error can be the CDN or the DDoS mitigation services. An important example is CloudFlare, where the 502 bad gateway error can occur in two different variants depending on the problem.
- This screen indicates that the problem is from CloudFlare and to solve it you need to contact your customer support team. Alternatively, you can choose to disable CloudFlare, but keep in mind that DNS propagation may take a couple of hours.
Contact customer support
- If none of the above solutions solved the 502 bad gateway error, you should contact the customer support team. When you describe the problem, remember to include the resolution procedures of the problem you have already adopted, provide as much information as possible so as to facilitate and streamline the assistance procedures and speed up the putting of the site online.