How to Fix the 502 Bad Gateway Error in WordPress

Posted on February 27, 2018 by in Tips & Tricks | 19 comments

How to Fix the 502 Bad Gateway Error in WordPress

One of the most frustrating aspects of running a website is having to troubleshoot an error when you don’t know why it’s happening. Some issues, such as the 502 bad gateway error, have many potential causes. This means you may need to try multiple solutions before you land on the right one.

If you understand a little about the error in question, on the other hand, you’ll have a head start when it comes to fixing it. In this article, we’ll talk about what the 502 error is and what can cause it. Then we’ll teach you how to troubleshoot the problem. Let’s get to work!

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

The 502 bad gateway error in action.

The 502 bad gateway error pops up from time to time, and often means there’s a problem with your server.

When you visit a website, your browser sends one or more requests to the server that hosts the site. If everything is working properly, that server will send back the information your browser asked for, and the website will load. On the other hand, the 502 bad gateway error occurs when a server sends back an ‘invalid’ response. This can mean that the connection timed out, or can be the result of several other issues.

So far, this may sound simple. However, the connection between your browser and most websites isn’t as straightforward as it used to be. For example, your browser’s request might get routed through a proxy server before making its way to the host in question, so it can be hard to pinpoint where the issue is located. A lot of websites also use multiple servers, which complicates things even further since any of them could be the cause of the 502 error.

All of this means there are a few potential causes for this particular error code. It could be the result of:

  • Errors in your database.
  • A server that is timed out, currently unavailable, or just not working as intended.
  • A problem with your reverse proxy server.
  • Faulty PHP scripts, courtesy of one of your plugins or themes.

The good news is that if the problem is with the server, you may not need to take any action. In these cases, your hosting provider will usually jump to the rescue quickly (since clients tend not to appreciate downtime).

With that in mind, we’re going to focus on what to do if the 502 bad gateway error doesn’t go away on its own quickly. Most websites can’t afford to be down for hours at a time, after all, so if this error persists it’s time to start troubleshooting on your end.

How to Fix the 502 Bad Gateway Error in WordPress (3 Potential Solutions)

Before you shift into troubleshooting mode, there’s one quick test you can run to determine if your server is responding as it should. You can try running a traceroute, to see if your server is reachable in the first place. If it is, then the problem is probably on your end. If not, you may want to get in touch with your hosting provider.

You should also try resetting your router, and checking your Domain Name System (DNS) settings. These are basic fixes that can sometimes make the 502 error go away, and they’re easy enough to tackle on your own. If you find that neither solution solves the problem, however, you can use the following methods to troubleshoot the 502 error.

1. Clear Your Browser Cache

The 502 error can appear when you try to access your website, even if the underlying problem has been resolved. This occurs if your browser is relying on its cache, rather than loading the latest version of your site from the server.

Simply reloading the site a few times can often do the trick. If it doesn’t, and you’re using Windows, you can try using the CTRL + F5 command. This forces your browser to reload the website and empty its cache, and it works across most browsers (including Chrome and Firefox). OS X users will instead need to use the CMD + CTRL + R command for Safari to achieve the same result.

If all of the above fails, you should proceed to empty your browser’s cache manually. Chrome users can do this by navigating to the Settings > Advanced menu, and locating the Clear Browsing Data option:

Clearing your browser's cache.

Look for the Cached Images and Files option under the Basic tab, and click on Clear Data after selecting it. Keep in mind that this menu will also delete your browsing history, if you don’t disable that setting before clicking on the Clear Data button.

This same process can also be completed using Firefox, SafariInternet Explorer, and just about any other browser. When you have cleared the cache, try reloading your website once more. If the error persists, it’s time to get serious.

2. Temporarily Disable Your Content Delivery Network (CDN)

Earlier, we mentioned that your browser requests will sometimes be routed through a reverse proxy server. In other words, using a proxy server places an intermediary between the user’s browser and the website’s server.

Some services, such as Content Delivery Networks (CDN), rely on reverse proxy technology to route incoming traffic as efficiently as possible. However, sometimes this extra layer can create issues when you’re trying to connect to a website’s origin server. When that happens, your visitors (and you) might run across the dreaded 502 bad gateway error.

Fortunately, it’s easy enough to check and see if your CDN is causing this issue. All you have to do is temporarily disable the service, and then test whether your website loads correctly without it. The process of disabling your CDN will vary depending on the service you’re using, but it’s usually simple.

For instance, Cloudflare users just have to navigate to the Overview tab in their dashboard. Inside, you’ll find a list of properties that are running the service. Then you’ll need to look for the big Pause button in the Pause Website section, and click on it:

Pausing your CDN service.

Now, when you try to access your website, its origin server will respond to the request without any middlemen getting in the way. If the 502 error is gone, then your CDN was probably the source of the issue. In most cases, you’ll just need to wait a few hours before re-enabling the service. Of course, be sure to check and make sure that the error is still gone afterwards.

If you’re using another CDN, you’ll need to look at its documentation for instructions on how to temporarily disable the service. However, if your CDN turns out not to be the problem, there’s one more fix you can try.

3. Test Your WordPress Themes and Plugins

So far, we’ve talked about three potential causes behind the 502 error: your server, your browser, and middleman services such as CDNs. That only leaves one option if you’re sure the problem is on your end, and that is your WordPress website. More specifically, one of your plugins or themes might be trying to execute a script that your server can’t load correctly. This can result in an invalid response when your browser sends a request, triggering the 502 error.

You can only have one active theme at a time, so you can simply deactivate your current one and switch to a default WordPress theme temporarily, to see if that resolves the error. On the other hand, figuring out if a plugin is causing problems can take more time, depending on how many of them are currently active.

Since you don’t have access to your dashboard at the moment thanks to the error, you’ll need to disable your plugins and themes manually. Keep in mind that this process doesn’t involve deleting the plugins and themes, and reactivating them only takes a moment. So your website’s functionality shouldn’t be affected. Even so, you should have a recent backup ready just in case.

Then, open up the FTP client of your choice. We’re big fans of FileZilla, so we’ll be using that as our example. Log into your website via FTP, and navigate to the public_html > wp-content > plugins folder. There should be a folder for each of your installed plugins inside – even those that aren’t active:

Your WordPress plugin directory.

If you right-click on any of those folders, you’ll see several options, including one labeled Rename. Click on that now, and change the name of the folder to something like disabled.pluginname:

A disabled WordPress plugin.

When you access your website now, WordPress won’t be able to find that plugin, so it will load without it. If the plugin you just deactivated was causing the 502 error, your website should load correctly. Just to be sure, remember to use the CTRL + F5 command (or the OS X equivalent) to force your browser to delete its cache before reloading the site.

To avoid confusion, you should troubleshoot one plugin at a time. Change a folder’s name, try reloading your website, and see if it’s still displaying the 502 error. If it is, restore the folder’s original name. Repeat this process with each folder until you’ve found one that’s causing the error, or until you’ve tested every plugin. You can use the same process to test your active theme, which will force WordPress to use one of its default themes instead.

If one of your plugins or themes is causing the 502 error, you can delete it altogether and look for a replacement. If it’s outdated, you can also try updating it, to see if that resolves the problem. In some cases, the problem script will be patched quickly, so you can always resume using that plugin or theme later on.


Troubleshooting WordPress errors is often easier than you might think. Even issues that have a lot of potential causes, such as the 502 bad gateway error, are well understood and documented. You might have to try out multiple solutions before you land on one that works, but the troubleshooting process shouldn’t take too long if you follow the right instructions.

If you run into the 502 bad gateway error on your website and it doesn’t go away after a few minutes, chances are the problem is on your end. In that case, here’s what you’ll want to try:

  1. Clear your browser cache.
  2. Temporarily disable your CDN.
  3. Test your WordPress themes and plugins.

Have you ever run into the 502 bad gateway error on one of your WordPress websites? Share your experiences with us in the comments section below!

Article thumbnail image by windwheel /


  1. The best option for sorting out errors (not CDN issues) is having decent hosting where you can check the server error logs in realtime.

    • John Hughes

      Hello Peter. Thank you for raising this valid point. In addition to the factors we have covered, a good hosting provider can prove invaluable for preventing log errors. 🙂

  2. Very good topic! Welldone on clear and easy explanations! Thanks a lot! Keep going! 🙂

    • John Hughes

      Thanks for the comment, Marcelo. Much appreciated. 🙂

  3. Thank you for this. I get these from time to time and this will at least give me some clues. Bookmarked!

    • John Hughes

      You’re welcome, Mark. Happy to help. 🙂

  4. Since I installed Divi on my virtual server (3 websites) I get 5xx errors, my server is down for few minutes from time to time.
    I changed some settings in PHP 7.2, like you recomend in the forum and it helped a bit. But maybe you should write an official recommended configuration for a server (best settings for PHP, nginx/apache, mysql)?

    • I am curious as to what you changed. I am on PHP7.0 – does 7.2 help with these 5xx errors? I have made the various changes to PHP.ini for memory allocation, etc. Thanks!

    • John Hughes

      Hello, xokko. Thanks for the suggestion – we’ll bear it in mind for future pieces! As for your issue, you may be better served contacting your host, just to check everything under the hood is working correctly. Hope this helps 🙂

  5. a very well explained and clear article. I think this will do

    • John Hughes

      Hi Gozie. Glad you found it helpful 🙂

  6. I agree with Peter up there…A good hosting is the easiest way to solve this issue. I used to encounter this issue when I was hosting my websites through Hostgator. I had to go through a couple hosting companies before I found the company I’m using now. I’ve been with this hosting company for over a year now and have yet to see the 502 error page.

  7. For those of you who aren’t adding a link in your posts, I hope you will consider including one to your site. I enjoy checking out what everyone is doing with Divi.

  8. These are certainly some helpful tips, especially as themes become constantly more complex and demanding on web servers. overall, I find that it can be plugins like that drag things down, even to the point of crash. Normally, clients come to us with Divi and on their own don’t understand hosting – so we’ve done well with helping them ensure pagespeed and uptime.

    • John Hughes

      Hi Christopher. Thanks for your comment. 🙂

  9. I only get it when trying to log-in to the dashboard – 502 – then I open another window and access the website – the black WordPress border shows up and I go to “menus” or another link and then I can access the dashboard. It doesn’t show up just accessing the website only when accessing the WP-admin page. Any clue what that might be? Thanks – great article BTW!

    • John Hughes

      Hello, Dick. We recommend contacting your host provider, as this could be the result of any number of issues. We also recommend the WordPress support forum, as that might provide further insight into the issue:

      Hope this helps, and glad you liked the article. 🙂

  10. Happened to me just recently and it was the latest theme update! Not Divi though… 😉

  11. Thanks for the post How to Fix the 502 Bad Gateway Error in WordPress. This is very good information on this topic as I have experienced this first hand.

Leave a Reply

Comments are reviewed and must adhere to our comments policy.

492,154 Customers Are Already Building Amazing Websites With Divi. Join The Most Empowered WordPress Community On The Web

We offer a 30 Day Money Back Guarantee, so joining is Risk-Free!

Sign Up Today

Pin It on Pinterest