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.
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.
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.
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.
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.
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.
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.
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
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