Home Wordpress How to Fix the 502 Bad Gateway Error in WordPress

How to Fix the 502 Bad Gateway Error in WordPress

by Mr. Geek Tips
0 comment

Trying to fix an error with your website that you don’t know what’s causing is one of the most frustrating things a site owner can go through. errors such as 502 Bad Gateway can have a variety of reasons, which means you’ll have to try a number of solutions before you find the right one. In this article, I’ll teach you how to fix the 502 bad gateway error easily.

What is a 502 Bad Gateway Error?

When you visit a website, your browser sends several requests to the server, and the server works to fulfill these requests; if everything goes smoothly, the server will send the information requested by the browser, and the site will appear within the browser; however, the 502 Bad Gateway error appears when the server sends an incorrect answer. This could indicate that the connection time has expired, or it could be the result of a variety of other problems.

502 bad gateway error chrome 1
502 Bad Gateway Error on chrome | source: Kinsta

So far, it appears simple, but the connection between the browser and the server is not as direct as it used to be; for example, your browser request may pass through a proxy server before reaching the requested server, making it difficult to locate the problem; and because many sites use multiple servers, this complicates the issue even more, as any of these servers may cause the 502 error.

There are various causes for this error, which appears as a result of the following:

  • errors in the database.
  • The server’s connection timeout has expired, the server is currently offline, or it is not functioning properly.
  • The server is processing far too many requests as a result of a DDoS attack, or it is receiving more traffic than expected during busy periods.
  • Problem with the reverse proxy server.
  • A PHP code error from one of the plugins or themes.

If the problem is on the server, all you need to do is contact the hosting support team and ask them to solve the problem after providing them with the error message that shows on your site.

I’ll focus on the important steps to do if the 502 error doesn’t fix quickly as it should since most websites can’t afford to remain down for hours.

How to fix 502 Bad Gateway error

Before you begin the troubleshooting process, you should do a quick and simple test to check whether the server is responding properly or not. Traceroute can be used to determine whether or not your server is reachable. If it is, then the problem is on your end; if it is not reachable, then the problem is on the hosting’s end, and you should contact its support team.

You should also restart your home router and check DNS settings; these steps may resolve the issue and are simple to carry out on your own. If neither of the first two solutions works, you can try one of the following steps to fix the 502 error.

1- Clear browser cache

Even when you try to access your site after you fixed the error, error 502 may still appear. This happens when the site depends on browser cache files rather than getting the most recent version of the site data from the server.

you can either delete the browser cache manually or by using an extension.

Google Chrome users:

  • At the top right, click the 3 dots.
  • Click More tools and then Clear browsing data.
  • Select All time, to delete everything.
  • Next to “Cookies and other site data” and “Cached images and files,” check the boxes.
  • Click Clear data.

2- Disable CDN Temporarily

We previously mentioned that browser requests can be passed through a proxy server, which acts as an intermediary between the user’s browser and the site server, and some services, such as content delivery networks (CDN), rely on reverse proxy technology to best direct incoming traffic, but this extra layer causes some issues when you try to connect to your site. One of the issues is the 502 Bad Gateway error.

You may simply determine whether the CDN is the source of the issue by temporarily disabling the service and then testing the site to see if it is operational again. The process of disabling the CDN varies depending on the service you use, however, it is usually a simple process with a click of a button.

disable cloudflare cdn

If you are a Cloudflare user, you can Navigate to the Overview tab in the control panel, and in Advance actions click Pause Cloudflare on Site.

If the 502 error disappears, it means that the problem was caused by the CDN, and you may need to wait a few hours before activating the service again, and make sure that the error does not appear again after reactivating the service.

If you are using a content delivery network other than Cloudflare, check its manual for instructions on temporarily deactivating it; however, if the content delivery network is not the issue, you should try the last option.

3- Check WordPress plugins and themes

So far, we’ve identified 3 possible causes of the 502 error:

your site’s hosting server, your browser, and services like CDNs. Sometimes an issue comes when it executes code that the server was unable to complete, and the following may result in the server responding incorrectly to your browser request, displaying error 502.

filezilla

Because you can’t access your WordPress dashboard right now, you’ll have to disable the plugins manually using an FTP client like FileZilla.
The best option is to disable all plugins, which you can do by changing the name of the folder by adding “.deactivate,” for this example, rename the folder “plugins.deactivate.”

If you change the names of the plugins folders, WordPress will be unable to find them when you visit the site again, as it will appear as deactivated, so if the error disappears after deactivating the plugins, this means that a plugin is responsible for the 502 error.

So, start activating the plugins one by one till you find the plugin that causes the problem and deletes it, or finds an alternative, then rename the plugins folder in Filezilla to what it was “Plugins”.

Conclusion

The steps mentioned above should resolve the 502 error, but if it continues, you should contact your hosting support team for assistance in resolving the issue.
Instead, you may join the Facebook group “WordPress Helps and Learn” and post your problem, I will personally assist you.

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

@Mr. Geek Tips 2022. All Right Reserved. Designed and Developed by Coders Xpress.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More