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

One error we occasionally come across when managing WordPress sites is the 502 bad gateway error. This particular issue can be quite frustrating because it can stem from various sources, and the error message itself doesn’t offer much guidance on how to resolve it.

As a team that’s dealt with numerous WordPress issues over the years, we understand how disruptive this error can be to your site’s operation. Whether you’re running a blog, an eCommerce store, or a business website, a 502 error can bring your online presence to a halt.

In this article, we’ll share our experience and walk you through 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.

🛠️ Need help with your website? Our WPBeginner Pro Services offer a comprehensive maintenance service kit to keep your website safe and secure at all times. We can do everything from uptime monitoring and malware removal to routine cloud backups.

Schedule a FREE Consultation Call With Our Team Today!

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

CDN services and WordPress firewalls sit between your visitors and your server. If they glitch, a 502 error can appear.

Log in to the service’s dashboard and pause it temporarily. Each provider labels this option differently, so follow its on‑screen steps.

Reload your site. If the error disappears, the CDN or firewall was the culprit. Contact its support team for a safe way to turn the service back on.

Still seeing 502? Let’s move inside WordPress and check themes and plugins next.

4. Update Your WordPress Themes and Plugins

Outdated or poorly coded themes and plugins can sometimes trigger the 502 bad gateway error. We’ve seen this happen a lot when a recent update conflicts with existing code or server settings.

To rule this out, deactivate all your WordPress plugins via FTP by renaming the plugins folder.

Renaming the plugins folder using FTP

Then reload your website. If the error disappears, you’ve confirmed that one of your plugins is the cause.

Now, restore the folder name and activate each plugin one by one until the error comes back. That’s the cause.

You can replace the broken plugin with a trusted alternative from our list of must-have WordPress plugins, or contact the plugin author for help.

If plugins aren’t to blame, your theme might be. Try switching your theme to a default one via phpMyAdmin and check your site again.

If your website loads fine now, then your theme was the issue and should be replaced or fixed by the developer.

If that didn’t work, then let’s move to the next step and try restoring your website to an earlier version from a backup.

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.

✅ Easy automatic backups
✅ Safely store backups on the cloud
✅ Restore your website with 1-click

We use Duplicator on all our websites including WPBeginner. See our full Duplicator review for more details.

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.

Alternatively, WPBeginner Pro Services offer emergency WordPress support if you still cannot pinpoint the root cause and address the problem. Our team can look into your website, figure out the problem, and resolve the error once and for all.

Feel free to schedule a free consultation call with our team today.

Emergency WordPress Support

Bonus: More Guides on Fixing WordPress Errors

If you’re seeing the 502 error, there’s a good chance you’ve run into other server-related issues too. Here are some other step-by-step guides that can help you troubleshoot similar WordPress errors and get your site working smoothly again.

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

4 CommentsLeave a Reply

  1. Dennis Muthomi

    YOu mentioned that high traffic as one potential cause of 502 errors. Could a DDOS attack also overload the server and show this error?

    • WPBeginner Support

      It is possible but normally it is high traffic :)

      Admin

  2. Piper

    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.

    • WPBeginner Support

      Thanks for your additional recommendation :)

      Admin

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.