How to fix 502 Bad Gateway on WordPress?

siddhant sugan dodrai
By -
0

One of the worst things about running a website is troubleshooting an error when you do not know why it is happening. Some issues like 502 bad gateway error have many possible causes. You may have to try several solutions before you find the right one. In this post, we will show you how to handle this difficult error and fix it. How to fix 502 Bad Gateway on WordPress?

How to fix 502 Bad Gateway on WordPress?


What the 502 Bad Gateway Error Is (And Why It Happens)

What the 502 Bad Gateway Error Is (And Why It Happens)

When you visit a site, your browser forwards one or more request(s) to the server hosting the site. If all goes well, the server returns the information your browser requested, and the website loads.

On the other hand, when a server returns an 'invalid' response, a 502 bad gateway error appears. This error may indicate that the connection was terminated prematurely, or it may be due to several other factors.

Here is the official definition from the Mozilla Developer Network:
The HTTP 502 Bad Gateway Server Error Response Code means that the server that acts as the gateway or proxy received an incorrect response from the downstream server.

As you can see, it all seems pretty straightforward. But the truth is, the way your browser interacts with most websites is not as simple as it once was. For instance, your browser's request might be sent via a proxy server before reaching the host in question. This can make it difficult to determine the source of the 502 error. Many websites also have multiple servers, which makes things even more complicated as any one of these servers could be the source of the error.

All of which means that there are several reasons why this error code might occur.

✔️ Database errors

✔️ Server that is out of service, currently out of service, or simply not working as expected

✔️ Server overloading due to too many requests

✔️ DDOS attack or just a large-than-planned spike in traffic

✔️ Problems with reverse proxy server

✔️ PHP scripts that are faulty, caused by one of the plugins or themes.

The silver lining is that if it’s a server-side issue, you may not have to do anything at all. In this case, your hosting provider is likely to act quickly (since clients don’t like to waste time). Make sure to get in touch with the support team of your host as soon as you receive the notification that your site is impacted by a 502 error.

This is why we are going to discuss what to do if 502 bad gateway error does not resolve on its own. After all, most websites cannot afford to be offline for hours on end. If this error persists, then it is time to troubleshoot on your side.

👉 How to Resolve wordPress White Screen Error?

How to fix 502 Bad Gateway on WordPress?

Before you go into troubleshooting, there is a simple test you can perform to check if your server is working as expected. You can run a traceroute to see if you can reach your server at all. If you can, then the issue is most likely with your hosting provider. If not, then you may need to contact them.
You can also reset your router, and check your DNS settings. These are simple fixes that can sometimes eliminate the 502 error, and they are easy to fix yourself. However, if you find that neither of these solutions fixes the 502 error, you can troubleshoot it using the following methods:

1. Clear Browser Cache 

The 502 error occurs when you attempt to access your site, even if you have solved the underlying issue. This error happens when your browser relies on its cache instead of loading the most recent version of your website from the site’s server. Just reloading your site a couple of times will usually fix the issue. This is especially true if you use the Forced Reload method on Windows (Shift-Ctrl-R) or Shift-Ctrl-R on your Mac.

If all the above doesn’t work, you’ll need to manually clear the cache in your browser. For Chrome users, this can be done by navigating to Settings > Advanced, and then selecting the ‘clear browsing data’ option.

Under ‘Basic’ tab, search for ‘Cached Images & Files’ and click on it. After selecting this option, click on ‘Clear Data’. Please note that this menu also deletes your browsing history unless you disable it before clicking on Clear Data.

You can also do the same thing with Firefox, Safari, and Internet Explorer, and almost any other browser. Once you’ve cleared the cache, reload your website again. If the error doesn’t go away, you’re ready to take action.

👉 How to Fix WordPress 403 error?

Disable Your CDN ( Content Delivery Network)

As we mentioned earlier, your browser’s request will sometimes be sent via a reverse proxy. In simple terms, a proxy server acts as a middleman between your browser and the web server.

Some services, like CDN (Content Delivery Network), use reverse proxy technology to optimize incoming traffic. However, this additional layer can sometimes cause problems when attempting to connect to a site’s source server. When this happens, your users (and you) may encounter the infamous 502 bad gateway error.

Fortunately, there are simple steps you can take to determine whether your CDN is the cause of this problem. All you need to do is temporarily turn off your CDN and then see if your website loads properly without it. The steps for turning off your CDN depend on the type of service you use, but they’re usually pretty straightforward.

For example, a Cloudflare user can visit the Overview tab in the dashboard. Inside, the user will see a list of properties running the service. Next, the user will need to find the big “Pause” button in the “Pause Website” section and click it.
Pause Your Cloudflare CDN

Now, when you attempt to access your site, its source server will respond to your request without any third-party intermediaries interfering.

If the 502 error is no longer present, then it is likely that your CDN was responsible for the problem.

Most of the time, you will only have to wait a couple of hours before re-activating the service.

Of course, you should check and see if the error is still present after a few hours.

If you are using a different CDN, you will need to check its documentation for how to disable the service temporarily. However, if it turns out that your CDN isn’t the issue, there is another fix you can try.

Disable Your WordPress Theme or Plugin

As mentioned above, there are three possible causes for the 502 error:

🔹 Your server
🔹 Your browser
🔹 CDN (Content Delivery Network)
🔹 Your website

If you’re confident that the issue is on your side, you’re in the right place. If you’re running WordPress, for example, one of your WordPress plugins or themes might try to execute a script on your server that your server cannot load properly. This can cause an error when your browser sends out a request, which triggers the 502 error.

Since you can’t have more than one active theme, you can simply turn off your current theme and temporarily switch to your default WordPress theme to see if the error is resolved.

However, checking for a plugin that is causing issues can take longer depending on the number of plugins that are active.

Since you are currently unable to access your dashboard due to this error, you will have to manually disable plugins and themes. Please note that this process does not require you to delete plugins and themes. Reactivating them will only take a few moments and will not affect the functionality of your website. However, you should still have a fresh backup ready. If you do not have a backup plan in place, check out this list of top WordPress backup plugins.

Open the FTP client you want to use. We use FileZilla as an example. Once you’ve logged in to your website using FTP, go to the plugins folder on your website. This folder should contain all your installed plugins, even the ones that are not active.

If you click on any of these folders, you will see a few options. Rename is one of them. Now, click on Rename and rename the folder name to something like disable.pluginname.
Disable plugin and rename plugin using filezilla


When you visit your site now, WordPress will not be able to load that plugin. So, your site will load without that plugin.

If the plugin you have just disabled is the one causing 502 error, then your site will load properly.

To make sure that your site loads correctly, use CTRL+F5 (or OS X equivalent). This command will prompt your browser to clear its cache before loading your site.

To avoid confusion, troubleshoot each plugin one at a time.

First, change the name of a folder.

Then, reload your website and see if the 502 error is still showing.

If the error is still there, restore the folder to its original name.

Do this for each folder until you find one that is causing the error or until you test every plugin.

The same process can be used to test the active theme.

Testing the active theme will cause WordPress to use its default theme instead.

If the plugin or theme causing the 502 error is one of the plugins or themes, you can remove it completely and search for a new one. If the plugin or theme is old, you can also update it and see if that fixes the issue. Sometimes, the issue script will be fixed quickly, and you can always use that plugin or theme again later.

Other Methods to Fix 502 Bad gateway Error

These fixes will most likely find and correct the cause of the 502 error if the error is caused by you and not by the server. If the error persists, we recommend contacting your web host so they can troubleshoot the server and fix the issue. However, you can reduce the time to troubleshoot by performing a few simple checks.

One of the first things to check is any logs your site may have saved. If you’re using WordPress, there are several ways to view this information. We’ve written extensively about how to use these logs to enhance your site, so that may be helpful here. WordPress sites running version 5.0 or higher have a Site Health tool built into their admin dashboard, so be sure to check what it says.

You can also ensure that your browser's cookies are clean. These are completely different from the cache and we don't always want to delete them. If you have any information stored in your browser this will remove it. However, these same cookies can also 502 the link between you and these sites, which can be a bit of a problem. In any case, it's relatively simple to delete the cookies on any major browser.

If your site just stops working, it could be because there is something in your site’s background that needs more time to run. A WordPress site’s execution time can be increased quite easily by editing the functions.php file in your site. If you are not on WordPress, you can do this using.htaccess or the file ‘php.ini.’

Finally, you can look for DNS errors. If you’ve migrated hosts or switched to a different type of plan or server, you may have changed nameservers, or any number of other things that can go wrong. DNS settings are extremely granular and prone to configuration errors. Go into cPanel or dashboard and double-check that everything is consistent between your host, your domain registrar, and your website’s settings. Sometimes a misconfiguration or a simple typo can derail everything. A bit of DNS proofreading can make all the difference.

You can also manually flush your DNS cache in the terminal if you want to make sure the DNS is working properly on your end.

In brief Step:

To troubleshoot a 502 Bad Gateway error on WordPress, consider these steps:

Check Hosting Server: Ensure your web hosting server is operational. Contact your hosting provider for assistance if needed.

Review Plugins and Themes: Deactivate plugins and switch to a default theme to identify if the issue is caused by a plugin or theme conflict.

Increase PHP Memory Limit: Increase the PHP memory limit in your `wp-config.php` file by adding: `define('WP_MEMORY_LIMIT', '256M');`

Check Server Logs: Review server error logs for more specific information about the error.

Test with Default .htaccess: Rename your existing `.htaccess` file and create a new, default one. Check if the issue persists.

Examine CDN or Proxy Issues: If you use a CDN or proxy service, ensure it's configured correctly and not causing the 502 error.

Update WordPress and Plugins: Ensure your WordPress installation, themes, and plugins are up-to-date.

PHP Version Compatibility: Verify that your WordPress version is compatible with the PHP version on your server.

Database Issues: Repair and optimize your WordPress database using tools like phpMyAdmin.

Server Resource Limits: Check if your server has sufficient resources (CPU, memory) to handle your website's traffic.

If the problem persists, consider consulting with your hosting provider or seeking assistance from a developer for a more in-depth analysis.

Conclusion

WordPress error troubleshooting is often simpler than you think. Even issues with multiple possible causes, like 502 bad gateway, are well documented and understandable. You may have to try several solutions before you find one that works. But if you follow the correct steps, the troubleshooting process should not take too long.

If 502 bad gateway error appears on your website and persists for more than a few minutes, or after a short call to your host's support team, it's likely that the issue is with you. Follow the processes and tricks outlined above and you and your visitors should be back up and running in no time.

Have you ever encountered 502 bad gateway errors on any of your websites? Let us know in the comments below!


Post a Comment

0Comments

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!