Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Fix the 502 Bad Gateway Error in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Are you seeing the 502 bad gateway error on your WordPress site?

This error is quite annoying because it can be caused by a lot of different things. Plus, the error message doesn’t provide exact pointers on how to fix it.

In this article, we will show you how to easily fix the 502 bad gateway error in WordPress.

How to fix the 502 bad gateway error in WordPress

What Is a 502 Bad Gateway Error?

A 502 bad gateway error happens when your WordPress hosting server gets an invalid response for the requested page. This issue can be caused by various things, and the error message may vary depending on your server.

502 bad gateway in browser

When a user visits a WordPress website, their browser sends a request to the hosting server. which then retrieves the page and sends it back to the browser.

If an error occurs, the browser displays an error status code, such as 502 Bad Gateway.

The most common reason for a 502 bad gateway error is that your request took too long for the server to respond.

The most common reason for this error is a delay in the server’s response to your request. This delay could result from temporary glitches due to high traffic, poorly coded WordPress themes or plugins, or server misconfigurations.

Other related error messages include 404 not found, 503 service unavailable, 403 forbidden error, and more.

Now, let’s take a look at how to easily fix the 502 bad gateway error in WordPress. Feel free to use these quick links to skip to a specific solution:

1. Reload Your Website

Sometimes, your server may take longer to respond due to increased traffic or low server resources. In that case, the problem could automatically disappear in a few minutes.

You should try reloading the web page that you are viewing to see if this is the cause. If this fixes your problem, then you do not need to read any further.

However, if you see this error frequently, then you will need to continue reading, as there may be something else that needs fixing.

2. Clear Browser Cache

Your browser may be showing you the error page from the cache. Even after the issue is fixed, you will see the 502 error because the browser is loading your website from its cache.

To clear your browser cache, read our guide on how to clear your browser cache in all major browsers. You may also want to clear your WordPress cache as well.

Clear browser cache

Additionally, consider using a different browser to troubleshoot if the problem is happening because of the browser cache.

Still seeing the error in all browsers? Go ahead and continue reading.

3. Disable the CDN or Firewall

If you are using a CDN service or WordPress firewall on your website, then their servers could be acting up.

To check this, you will need to temporarily disable the CDN or firewall. This process will be different depending on which service you are using.

Once disabled, it will remove the additional layer that has been created between your browser and the hosting server. Your website will now load entirely from your server. If the issue was caused by the CDN or firewall service, then it should be resolved now.

After that, you can contact your firewall or CDN service provider for support and solutions on how to enable it back properly.

4. Update Your WordPress Themes and Plugins

At times, the 502 bad gateway error may be caused by outdated themes and plugins. To see if this is true, you have to check them one by one.

First, you will need to deactivate all WordPress plugins via FTP. After that, visit your website to see if the error has been resolved.

If it has, then one of your plugins was causing the issue. You now need to activate all plugins one by one until you can reproduce the error. This will help you locate the plugin responsible for the error.

You can then look for an alternative WordPress plugin or contact the plugin author for support.

If deactivating plugins didn’t solve your issue, consider checking your WordPress theme. You will need to switch your WordPress theme via phpMyAdmin.

After switching your theme to the default WordPress theme, visit your website to see if it’s working.

5. Restore a WordPress Website Backup

For people using a backup plugin with their backups stored in a remote storage location, it may be a good time to restore one of these backups. This way, you can get your website back up and running just like before the error occurred.

For more information about backup restoration, read our beginner’s guide on how to restore WordPress from backups.

Now, if this solution fails as well, then you may want to consider this next step.

Expert Tip: Backups are an easy way to keep your website safe from unexpected errors or disasters. If you are wondering which backup plugin you should use, then we recommend Duplicator.

6. Check for PHP Timeouts

Sometimes, the cause behind the 502 bad gateway error is PHP timeouts.

A script on your website may take an unusually long time to execute, exceeding the time limit set by the server. This can happen due to complex calculations, database queries that drag on forever, or poorly optimized code. When this occurs, a PHP timeout error appears.

By checking for PHP timeouts, you can identify these sluggish scripts that might be causing the 502 bad gateway error.

There are a few ways to check for PHP timeouts. One is to enable debug mode, which can provide some PHP error information.

You can also read our guide on how to fix Fatal Error: Maximum Execution Time Exceeded in WordPress as this tutorial focuses on PHP timeouts.

7. Contact Your Hosting Provider

The last solution is to reach out to your web host’s support, as it’s also likely that the issue is on their end.

If not, they can also help you with checking your server’s error logs to see what’s happening to your website.

Make sure to let them know about the issue and mention all the troubleshooting steps you have taken. All good WordPress hosting companies will be able to quickly fix the issue if it was caused by a server misconfiguration.

You can also check out our guide on how to properly ask for WordPress support and get it.

We hope this article helped you learn how to fix the 502 bad gateway error in WordPress. You may also want to see our complete WordPress troubleshooting guide and our expert picks for the best email marketing services to grow your website.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

3 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Piper says

    Just a suggestion really. If the error is only when you try to go directly to wp-admin or anything on the admin area, it may be because the wordpress site cannot log you in. If you have security which limits your login attempts this may be the case. Try logging in as a user first and see if it warns you to ‘try again in 20 minutes’ or similar. Waiting should fix this issue.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.