Menu Close

How to Fix a 502 Bad Gateway Error in WordPress


Any error that makes your WordPress site unusable is a serious cause for concern because it means lost revenue, poor SEO rankings and a lot of undue stress for you. One of the most notorious errors to ever grace the internet is the 502 bad gateway error. It’s a nasty and frustrating problem because it can crop up due to a number of reasons, which make it hard to troubleshoot and fix.

Not to worry though, we have your back. If you’re looking to fix the 502 bad gateway error on your WordPress site, take a breather hombre because we offer you a couple of tried-and-tested solutions. By the end of today’s post, you should get rid of the 502 bad gateway error once and for all.

If that sounds like the kind of deal you wouldn’t dream of passing up, grab yourself a mug of coffee and let’s roll.

What is a 502 Bad Gateway Error?

First things first, what in the name of asking is a 502 bad gateway error? Here’s a tiny lesson on matter hosting. Hosting your WordPress site usually involves a couple of servers.

The most basic setup may involve four to five(ish) servers namely:

  • An application server that processes your PHP code and any other dynamic content on your site
  • A database server where your databases live
  • Reverse proxy server e.g. Nginx and Apache that controls which HTTP requests go where
  • The web server that stores all of your static files such as images, CSS and JavaScript
  • A CDN (optional performance server)

Now, when you enter your site URL into your browser and hit ENTER, the browser sends a couple of HTTP requests to the reverse proxy server.

The reserve proxy server then routes the requests to the respective servers. For example, requests for the data stored in your database are routed to the database server. Requests for static files are routed to the web server, and requests that require PHP are processed by the application server.

Each server then sends back data to the reverse proxy server, which then send the data to your browser and your website loads. Simple as A, B, C – don’t let tough words such as reverse proxy confuse you.

If one of the servers sends an invalid response to the reverse proxy server, your website doesn’t load in your browser as expected. Instead, the reverse proxy server shows you a 502 bad gateway error.

An Animal Of Many Different Forms

The 502 bad gateway error can and takes many different forms such as:

  • Error 502
  • 502 Bad Gateway NGINX
  • 502 Proxy Error
  • 502 Service Temporarily Overloaded
  • HTTP Error 502 Bad Gateway
  • 502. That’s an error. The server encountered a temporary error and could not complete your request. Please try again in 30 seconds. That’s all we know.

What Causes a 502 Bad Gateway Error?

While the 502 bad gateway error usually happens on the server side, it can also occur due to problems on your end. Here are a couple of reasons why you are facing the 502 bad gateway error in no particular order:

  • Your upstream server may be overloaded due to a traffic upsurge
  • An offline server will throw the 502 bad gateway error into your face
  • Server mis-configurations that might aside due to a number of reasons such as human error especially when your host move servers
  • Problems with your content delivery network (CDN)
  • Misbehaving browser cache
  • DNS issues
  • Faulty PHP code thanks to a problematic plugin or theme

As you can see from our short list above, the 502 bad gateway error can be caused by a number of things. This means you have to try different solutions to fix the error.

That being said, let’s troubleshot and fix the 502 bad gateway error on your WordPress site.

How to Fix a 502 Bad Gateway Error in WordPress

While this error might seem problematic to the average Joe, it’s actually incredibly easy to fix. You just need a little patience to try the following solutions.

1. Refresh/Reload Your Site

As we’ve already mentioned, most times the infamous 502 bad gateway error happens on the server side, more so if you’re on shared hosting. A sharp spike in traffic might exhaust your server resources leaving you in the thrall of this nasty error. Other times, your servers might be acting up or offline due to a number of reasons.

Hosting providers usually resolve the problem immediately because website owners loathe downtime with a passion. Plus they lose revenue whenever sites are offline.

So before you pull out your hair and suffer panic attacks, try refreshing your WordPress site a couple of times to see if the error clears on its own. Additionally, try a different browser or device to see if the error resolves itself. Still, to ensure the problem isn’t on the server side, test your site using a tool such as

However, if the error persists after trying the above fixes, move on to the next solution in this post.

2. Clear Your Browser Cache

Are you unable to fix the 502 bad gateway error even after refreshing your browser? If so, perform a hard-refresh on your browser (CTRL + F5 on Windows systems and CMD + CTRL + R on OS X systems). Does performing a hard-refresh get  rid of the nuisance that is the 502 bad gateway error? No?

Well, you can try clearing your browser cache directly using the tips we outline in how to clear WordPress cache. Is the nasty error gone after clearing your cache? If so, stop reading and do a happy dance. A back-flip even. Jokes aside.

If you’re still stuck with the error, the following solution might help.

3. Disable Your CDN Temporarily

Do you use a content delivery network such as CloudFlare, KeyCDN or another CDN for WordPress? CDNs usually route your website traffic to their servers to offer you better site performance and security.

A problem on their servers could leave you with the 502 bad gateway problem. Additionally, you can land on the 502 bad gateway error if you configure your CDN incorrectly.

To find out if your CDN is at the bottom of your 502 woes, pause the CDN and refresh your site. This forces your site to load directly from your host servers.

Is the error gone after pausing your CDN? If so, keep the service paused and contact their support department. Usually, they resolve the problem quickly, which means you will have to do without the CDN for a short while.

Each CDN has a different interface, meaning you need to check with your CDN on how to pause the service. From my experience, however, pausing a CDN is as easy as pie, so I don’t expect you to run into any problems.

4. DNS Problems

DNS (short for domain name system) is how domain names (e.g. match to their respective IP addresses. If something is a miss with DNS settings, you can expect the 502 bad gateway error among other problems.

Have moved to a new host recently? Migrating involves re-configuring your DNS servers. DNS propagation takes time, sometimes as long as 48 hours or more.

If you’re facing the 502 bad gateway error after migrating, wait for your DNS changes to propagate, of if need be, contact your host for further advice and help.

And since we are talking about DNS, you can also try to flush your local DNS cache. For Windows users, open your command prompt (cmd.exe) and run the following command: ipconfig /flushdns. As a Mac OS X user, run dscacheutil -flushcache in the command terminal.

5. Check Your Theme and Plugins

Can’t seem to fix the error so far? Perhaps the problem lies in your plugins or theme. Your theme or one of your plugins could be firing a script that doesn’t play well with your server.

As a result, the server kills the script, which causes the 502 bad gateway error. What to do? Let us start with your plugins.

6. Troubleshooting Plugins

You probably can’t login into your WordPress admin dashboard courtesy of the error. How then will you troubleshoot plugins without access to the WordPress admin?

Well, it’s simple. Login to your WordPress root directory (usually, it’s public_html but could be something else depending on where you installed your site) using either an FTP app such as Filezilla or File Manager in cPanel.

After that, navigate to wp-content and locate the plugins folder. Rename the folder to something like plugins.old to deactivate all of your plugins at once. Worry not, you won’t lose any data.

Refresh your site to see if the error is gone. If you see your site instead of the error, one of your plugins is the problem.

Rename plugins.old back to plugins and login to your WordPress admin dashboard. It’s time to find the problematic plugin.

Activate the plugins one by one while reloading your site after each activation. Repeat this until you pinpoint the plugin that is causing trouble. The problematic plugin will obviously recreate the 502 bad gateway error on activation, which might lock you out of the admin area.

Deactivate or eliminate the plugin completely via FTP or File Manager, get an alternative or contact the developer for further support.

7. Troubleshooting Your Active Theme

If your troubles began after updating your site i.e. themes, plugins and WordPress, and deactivating plugins doesn’t fix anything, you need to troubleshoot your WordPress theme.

Checking if your theme is the problem is a bit different from troubleshooting plugins. Let’s get it over and done with.

Login to your WordPress root directory via FTP or File Manager. Then navigate to wp-content > themes and locate your active theme.

Rename the active theme folder to something like total.old. This will deactivate the active theme and activate the default WordPress theme.

Reload your site to check if the error is gone. Is the error still there? It means your theme is okay, in which case you should rename the theme folder back to its original name.

If the error disappears, contact your theme developer for more help, or invest in a professional built theme such as our very own Total.

8. If The Problem Persists, Contact Your Host

Still can’t seem to fix the 502 bad gateway error on your WordPress site even after trying all the above solutions?

Perhaps the problem is on the server side, so just contact your host and get professional help. While at it, consider investing in a top-level host to avoid this error due to lower server resources available on shared hosting plans.


While a bit confusing and frustrating, fixing the 502 bad gateway error is easy with the solutions we outline in this post. We hope our post pointed you in the right direction in this regard.

Do you have any thoughts, questions or extra fixes? Help us expand this post by sharing your tips, queries and ideas in the comment section below.

View Source
Posted in WordPress