Many times surfing the internet we have come across this error on a web page.
Our browser sends various requests to the web servers where the pages are hosted. The servers handle these requests and send an HTTP status code along with the requested resources.
The 502 bad gateway error is an HTTP status code that we can encounter.
Normally this error is not frequent, the most frequent are still errors 500 and 503.
Whenever we find an error code that begins with the number 5, it will be an HTTP status error, and will occur due to lack of communication between servers.
A 502 bad gateway error means that the origin server sent an invalid response to another server that acted as a gateway or proxy.
Considering that all requests on the web are sent through multiple gateways, locating the exact point or process that caused the problem is very tricky.
But we have several ways to solve this type of error and that we will list below.
1. Reload The Website
The solution that may seem simpler, but that may be the most effective, wait one or two minutes and reload the page that is giving us the error.
Sometimes the server may take longer to respond due to increased traffic or low server resources. By doing this we can solve the problem, it is a possible option.
2. Clear Browser Cache
If reloading the page does not solve the error, we may think that there is something in the cache that is causing this problem.
To clear the cache we have two methods, either from the browser configuration, or through a shortcut, for Windows by pressing the Ctrl + F5 buttons and for Mac OS by pressing the CMD + Shift + R buttons on the keyboard to refresh the page.
3. Try Other Browser
We can do this check in a very simple way, checking the connection status from another browser.
So we remove from the equation the possibility that the error is given only and exclusively by our browser.
4. DNS Problem
A DNS problem can be the cause of a 502 error, such as the domain is not resolving the correct IP.
We may have just migrated our website to a new host, in this case it is important to wait for the DNS to fully propagate, which can take up to 24 hours in some cases. This depends on the TTL value of your DNS records.
Something similar to clearing the browser cache, is to refresh (flush) the local DNS cache.
To do this in Windos, just open the CMD command prompt and type: ipconfig /flushdns.
This action should return a message “Successfully flushed the DNS Resolver Cache” if it worked.
If we are working with a MacOS, we open a terminal and write the following script: dscacheutil -flushcache.
In this case we will not get any kind of message.
5. Error Log
The 502 error may have appeared after some change or update, and it is possible that this error was found within our website.
We have an option to verify if this is the case, and that is to enable error logging.
By default it is disabled, but we can enable it by adding the following lines in wp-config.php:[php] define( ‘WP_DEBUG’, true );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
6. Update WordPress Themes and Plugins
If we still have not solved the problem, we have the option to review the theme and plugins.
We start by disabling all WordPress plugins via FTP, and we’ll check if the error persists. In case it has been solved, we will activate the plugins one by one, until we find the one that causes the problem.
If this doesn’t work, we deactivate the WordPress theme and check if the error persists. If the error does not appear, then the theme is the one that is causing the problem.
In the latter case, we will contact the creator of the theme to give us a solution.
7. Hosting Server
One of the main reasons we can get a 502 Bad Gateway error is due to a problem with the web host.
Perhaps a query, script or request will take too long, in this case it is canceled or killed by the server.
Kill Script is typically implemented by a large number of hosts, especially shared hosts.
This basically what it does is terminate a request after a certain period of inactive time, this prevents our site from crashing.
If you have not created your website yet, you may be interested Create Your Website With WordPress.
Leave a Reply