Fix 502 Bad Gateway Error on Your WordPress Site With 10 Simple Ways

Troubleshoot and Fix 502 Bad Gateway Errors on Your WordPress Website

The 502 bad gateway error is one of the most common and most annoying errors you’ll see while online. It happens in WordPress, it happens when browsing random websites, when checking webmail and can literally happen anywhere on the internet.

The 502 bad gateway error is an HTTP error. That usually means something has interrupted the normal process between the web server and your browser. Exactly what interrupted it remains to be seen.

As you’ll see in a minute, there are a multitude of causes of 502 errors and it’s usually a process of elimination to identify that cause.

While this article is concerned with 502 bad gateway errors on a WordPress website, we won’t actually know if it’s the website or not until we have done a few checks.

Therefore, we’ll cover all the relevant troubleshooting steps you can take to identify whether it’s your website or something else.

We’ll also provide fixes for the vast majority of the causes of 502 errors as part of the process.

What Is a 502 Bad Gateway Error?

502 bad gateway error example

A 502 bad gateway error means a proxy server somewhere between your browser and the website or application you’re trying to contact received an invalid response from further up the chain.

When you type a URL into your browser, the browser will query DNS and be pointed towards the web host that hosts that website.

That host will use a proxy or load balancer to manage traffic. It will receive the query from your browser and send its own query to the web server hosting the website.

If the response it receives from the hosting server is all good, the page loads.

If the response is corrupted, fragmented or not understandable by the proxy, you’ll see the 502 bad gateway error.

HTTP errors are interpreted by the browser you’re using or the service you’re accessing so you might see variations of the error.

Those variations include:

  • HTTP Error 502 Bad Gateway
  • HTTP 502
  • 502 Service Temporarily Overloaded
  • Temporary Error (502)
  • 502 Server Error: The server encountered a temporary error and could not complete your request
  • 502 Bad Gateway Nginx
  • 502 bad gateway Cloudflare

They all mean the same thing but reference the service you’re accessing or the CDN the website is using.

Bad Gateway

The vast majority of 502 bad gateway errors you’ll see are network errors and will have nothing to do with you as a user.

There are local causes, such as browser issues, your router or local network and we’ll show you how to troubleshoot those in a little while.

If you’re a website owner and you are seeing this error from your own site, that’s a different story altogether!

We will show you some checks you can make on your website to make sure it isn’t your WordPress configuration, theme or plugin causing the error.

What Causes the 502 Bad Gateway Error?

There are a few situations that can cause a 502 bad gateway error.

  • Some errors are caused locally by your browser or local network
  • Some can be caused by a CDN, Content Delivery Network
  • Others can be caused by the web server itself
  • Issues with WordPress such as plugins and themes can also cause 502 bad gateway errors

We will show you how to identify likely causes of 502 bad gateway errors and how to fix them in a minute.

What Effect Does the 502 Bad Gateway Error Have?

google 502 error example

The effect of 502 bad gateway errors depends on the situation.

If you’re a user trying to access a website, seeing a 502 bad gateway error is an inconvenience you can avoid by visiting another site.

If you’re a WordPress website owner and are seeing 502 bad gateway errors on your own site, things are a little more serious.

Your visitors may also be seeing 502 bad gateway errors and not be able to reach your site.

Google may choose that moment to crawl your website and will also see the 502 bad gateway error. That will have a negative impact on your SEO until you get the site back up and running.

How to Fix the 502 Bad Gateway Error

There are a range of fixes for the 502 bad gateway error. Some of these will be relevant to general web users as well as WordPress website owners.

Let’s tackle the fixes in order of complexity with the easiest first. That way, we can minimize the work we need to do to get things working again.

1. Reload the Web Page

Reloading the web page is a useful first step as it takes just a second. We want to force a reload to make the browser request a new copy of the page rather than use its cached version.

For a forced browser refresh use one of these combinations:

  • Chrome on Windows: Ctrl + F5
  • Chrome on Mac: Command + Shift + R
  • Firefox on Windows: Ctrl + F5
  • Firefox on Mac: Command + Shift + R
  • Safari: Command + Option + R
  • Microsoft Edge: Ctrl + F5

2. Clear Your Browser Cache

Clear Your Browser Cache

Clearing your browser cache deletes all saved files, including cached copies of web pages saved for efficiency.

A browser will save a copy of a recently visited page and will show it if you visit the same page multiple times. The intent is to save time and deliver the page quickly but it can get in the way when troubleshooting.

Use one of the following combinations or menu options to access the cache page in your browser:

  • Chrome on Windows: Ctrl + Shift + Delete
  • Chrome on Mac: Command + Shift + Delete
  • Firefox on Windows: Ctrl + Shift + Delete
  • Firefox on Mac: Command + Shift + Delete
  • Safari: Settings > Safari > Clear History and Website Data
  • Microsoft Edge: Command + Shift + Delete

Once you have the data window open, select the option to delete browsing data and cached data. Then retest the website you’re trying to access.

3. Check IsItDown

Check IsItDown

Is It Down Right Now is one of the most useful websites on the internet. It’s a web-based tool that can check any website or web service to see if it’s working or not.

It’s useful as it can tell you whether the website you’re trying to access is up and it’s just you that cannot reach it or whether the site itself is down and nobody can reach it.

It’s a very reliable way to figure out whether the 502 bad gateway error is a error or part of a larger network or internet issue.

4. Check Device DNS Settings

flush your dns

DNS issues can cause you to see 502 bad gateway errors so that’s what we’ll check next.

You can flush your device’s DNS cache or change your DNS server. Both can, in theory, fix a 502 error.

To flush your DNS:

  1. Open a terminal in Windows or Mac
  2. Type ‘ipconfig /flushdns’ and hit Enter in Windows
  3. Type ‘dscacheutil -flushcache’ and hit Enter on Mac
  4. Retry the website before going further

You’ll see a success message in Windows but Mac won’t tell you anything.

If you’re still seeing 502 errors, you could try changing your DNS settings. You can do that on your device or on your router.

Check device DNS settings

In Windows:

  1. Type ‘ethernet’ into the Windows search box and select Ethernet properties
  2. Select Change Adapter Options in the window that appears
  3. Right click your Ethernet adapter in the next screen and select Properties
  4. Select Internet Protocol Version 4 (TCP/IPv4) in the center pane and select the Properties button underneath
  5. Select the ‘Use the following DNS server address’ option
  6. Enter 8.8.8.8 and 8.8.4.4 for Google DNS or 208.67.222.222 and 208.67.220.220 for OpenDNS
  7. Select OK

On Mac:

  1. Select System Preferences and Network
  2. Select Advanced and the DNS tab
  3. Select the ‘+’ icon to add a DNS server
  4. Enter 8.8.8.8 and 8.8.4.4 for Google DNS or 208.67.222.222 and 208.67.220.220 for OpenDNS
  5. Select OK and then Apply

If you have DNS set on your router rather than your device, you’ll need to log into the router and change it there.

If you landed on this blog post because you’re seeing 502 errors and don’t own a website, you’re at the limit of what you can do.

Our suggestion now would be to leave the website or service you’re trying to use for a while and try again another day.

If you’re a WordPress website owner and are troubleshooting 502 errors on your own website, your work is not done.

5. Disable Your WordPress CDN

Cloudflare 502 error

If you use a CDN, Content Delivery Network, on your WordPress website, you could try disabling that. As the proxy server your browser talks to will then need to talk to the CDN server, it could be that server giving the 502 bad gateway error.

If you use Cloudflare and are seeing the custom 502 bad gateway Cloudflare page in your browser, you have two options.

If you see the screen in the image above, the fault is likely at your web host.

If you see the blank white screen with ‘502 Bad Gateway cloudfare’ the fault is likely at Cloudflare. You can check on the Cloudflare service status page.

If you use another CDN, temporarily disable it through your web host’s control panel and retest the site.

If it works, the CDN is at fault so you would need to troubleshoot further with your host or CDN provider.

If the 502 error is still apparent, you’ll need to continue troubleshooting.

6. Disable Your WordPress Firewall

Disable Your WordPress Firewall

If you use a firewall or security plugin, and you should, now is a good time to troubleshoot that. Firewall configuration issues can cause 502 bad gateway errors and disabling the firewall is a simple test to find out.

  1. Log into WordPress as normal
  2. Select your security plugin and the firewall option
  3. Disable the firewall
  4. Open your website in another browser tab and retest

If the page loads as usual, it is likely your firewall configuration blocking traffic and causing error 502.

If the error is still apparent, enable your firewall again to protect your website and continue down this list.

7. Test Your WordPress Plugins

Have you added any new WordPress plugins lately? Have any of them updated to a new version? Either situation could cause 502 errors, so let’s tackle those next.

To save time, let’s disable all plugins to begin with.

  1. Navigate to Plugins and Installed Plugins
  2. Check the box at the top next to the word Plugin.
  3. Select the Bulk Actions menu and select Deactivate
  4. Select the Apply button next to it

Retest your website. If it works now, it’s a plugin at fault. Enable one plugin at a time and retest your site. As soon as you see 502 errors again, disable the last plugin you enabled. If your site works, it’s that plugin causing all your problems.

If the error still appears, it’s not a plugin. Feel free to enable them all again and move on to the next fix.

8. Test Your WordPress Theme

A well-coded WordPress theme should never cause error 502 but sometimes bad scripts can cause the server to not respond as expected.

Bad scripts could mean poorly coded or nefarious scripts like those you find in nulled themes. This is one reason everyone recommends never using nulled themes!

To check, let’s enable the default Twenty Twenty-One theme in WordPress.

  1. Select Appearance and Themes in your WordPress dashboard
  2. Hover over Twenty Twenty-One and select Activate
  3. Wait until the new theme has activated and retest in your browser

If the 502 error remains, you can switch back to your main theme.

If the error goes away, it’s your theme and you’ll need to follow up with the developer or use a better theme like Astra!

9. Check Your Server Logs

Check Your Server Logs

If it isn’t your CDN, WordPress plugins or themes, it may be an issue with the web server or one of the services you have running on it.

To find out, we’ll need to access your server logs.

If your host uses cPanel, accessing server logs is easy.

  1. Log into cPanel
  2. Navigate to Metrics and select Errors

If the server picked up errors, they should appear in the window.

Work through any errors you see to try to identify what’s causing 502 errors. It may take a while but you should be able to identify the cause from there!

Web hosts that don’t use cPanel will have their own log tools. Explore your control panel to find it.

10. Increase the PHP Timeout Limit

Increase the PHP Timeout Limit

We’re not huge fans of increasing the PHP time limit in WordPress. While it can fix numerous errors, including 502, it’s a workaround not an actual fix.

The real fix would be to identify the PHP script that’s taking so long and fix that, but it isn’t always possible. As increasing the PHP timeout limit is possible, it’s all we can do.

To increase the time limit, you’ll need to modify your php.ini file. This controls various elements within WordPress that interact with PHP.

Here’s how to do it.

You’ll find php.ini in your website root in root directory of your web host under public_html.

  1. Log into your web host and load cPanel or whatever control panel your host uses
  2. Navigate to your root folder public_html
  3. Right click php.ini and select Copy
  4. Name the new file php.ini.bk
  5. Select the original file and add the following code to the end then select Save
max_execution_time 300

This tells PHP to allow 300 seconds for a script to complete before it errors or terminates the script. While unlikely to cause a 502 error, it has been known, so is a viable troubleshooting method.

If you got this far and will haven’t fixed error 502, we recommend engaging with your web host’s customer support.

Explain what’s going on and explain the steps you have taken and work with them to troubleshoot from there. A good web host will do everything they can to get your site back online again so you should be in safe hands.

Can You Prevent 502 Bad Gateway Errors?

You cannot effectively prevent 502 bad gateway errors as many of the causes are out of your control.

As a web user, the vast majority of times you see the error it will be caused by far end network issues. As long as you work through your local checks, that’s all you can do.

As a WordPress website owner or administrator, you have a few more checks to make but again, the majority of times you see this will be a far end network issue or a server issue.

502 Bad Gateway Errors

That’s everything we know about 502 bad gateway errors and how to identify and fix them.

The majority of times you see the error, it won’t be you at fault, but those times when it is, you now have all the information you need to identify and fix it.

Just work your way methodically through this series of fixes and retest between each. If it’s anything to do with your own device or network, you’ll soon find out.

As a WordPress website owner, you have more work to do but even then, it’s very straightforward to check to see if it’s your website at fault.

After that it’s time to talk to your web host!

Do you have any other reliable fixes for 502 errors? See something we missed? Have anything to add? Share your thoughts in the comments below!

Join 635,020 Subscribers

Get exclusive access to new tips, articles, guides, updates, and more.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Download is Just A Click Away!

Be among the first to try the beta version of Astra’s Header Footer Builder. Filling the form will ensure you’ll be the first to learn about updates and features.

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.