Are you frustrated by seeing the dreaded "502 bad gateway" error on your WordPress site? This annoying message pops up when there‘s a network issue between servers, often leaving you scratching your head as to the cause.
Don‘t panic! While a 502 error can be caused by multiple things, it‘s usually fixable with some basic troubleshooting. In this guide, we‘ll walk you through what a 502 bad gateway is, the common causes, and 10 solutions to get your WordPress site humming again.

What Is a 502 Bad Gateway Error?
First, let‘s clarify what a 502 bad gateway means. This HTTP status code indicates that one server (acting as a "gateway" or "proxy") received an invalid response from another server upstream when it tried to fulfill the request.
In other words, your web server isn‘t getting a valid response from another server that it‘s relying on, like PHP or the database. So it displays the 502 to indicate something‘s wrong.
While it‘s often on the server side, the full list of potential causes includes:
- Overloaded server due to high traffic
- Faulty firewall or CDN configuration
- Corrupted WordPress core files, plugins or themes
- Exhausted server memory limit
- Issues with PHP or database servers
- Network connectivity problems
Now that you have a high-level understanding of this error, let‘s dive into the solutions!
How to Fix a 502 Bad Gateway Error in WordPress (10 Methods)
We‘ve ordered these solutions from simplest to most advanced. We recommend starting at the top and working your way down the list until your site is back online.
1. Refresh the Page and Clear Your Browser Cache
Sometimes the 502 error is temporary, caused by an intermittent network or server issue that resolves itself after a few minutes. Therefore, the first thing to try is simply waiting a minute and reloading the page.
Also clear your browser cache or open the page in Incognito/Private mode to rule out any browser caching issues. Chrome, Firefox and other browsers occasionally cache the 502 page, showing it even after the issue is fixed.

If the 502 error was a momentary glitch, this should bring your site right back. If not, proceed to the next solution.
2. Temporarily Disable Your CDN and Firewall
If you use a Content Delivery Network (CDN) service like Cloudflare or a Web Application Firewall (WAF), they could be interfering with requests to your origin server. Misconfigured rules can block legitimate traffic.
To troubleshoot, temporarily disable your CDN/WAF and see if the 502 goes away. Access your WordPress site directly via the origin server IP address instead of the domain (e.g. http://192.0.2.1 instead of http://example.com).
If this resolves the 502, you‘ll need to work with your CDN/firewall provider to identify the problematic rule and get it fixed. Keep them disabled until then.
3. Update WordPress Core, Themes and Plugins
Outdated versions of WordPress core, themes or plugins can cause compatibility issues that lead to 502 errors. Bugs in old code may be triggering improper server responses.
Access your WordPress admin dashboard and update everything to the latest versions available:

If a core update is available, start there. Then update your active theme and plugins one by one. After each update, refresh your site to see if the error clears.
Avoid updating everything at once, as this makes it hard to pinpoint if a specific update triggered the 502. Slow and steady is best for troubleshooting.
4. Restore a Recent Backup of Your WordPress Site
If the error started happening after a recent change, like installing a new plugin or editing code, the fastest way back may be restoring a previous backup.
Assuming you have backups (which you always should!), access your backup plugin or service dashboard and locate a restore point from before the 502 started. Download the backup files.
To restore, you‘ll need to overwrite your current WordPress files and database via FTP/SFTP and phpMyAdmin respectively. Follow the restoration steps from your specific backup tool:

After restoring the backup, the 502 will likely disappear as your site reverts to its previous state. You can then retry the recent change more carefully to avoid breaking it again.
5. Contact Your WordPress Host About Server Issues
If none of the above worked, there‘s a strong chance the 502 error is originating from your WordPress hosting provider‘s server. It could be a configuration issue, bug, or hardware failure.
Reach out to your host‘s support through live chat or a ticket system. Provide details on the 502 error, your WordPress setup, and troubleshooting steps you‘ve tried. They can check server logs to locate the underlying issue.
Quality managed WordPress hosts like WP Engine, Flywheel and Kinsta have expert support teams to quickly resolve server problems. If you‘re on cheap shared hosting, a resolution may take longer.
6. Upgrade Your Server Resources If Traffic Spiked
Did your WordPress site just go viral? Sudden spikes in traffic can overwhelm your server‘s CPU and RAM, causing it to falter and emit 502 errors.
To confirm, open your hosting dashboard and check metrics like CPU usage, memory usage and active visitor count. If any are pushing the limits of your plan, it‘s time to upgrade.
Consider moving up to a higher-tier plan with more server resources. Or switch to a hosting provider that can better handle your new scale. For high traffic sites, a dedicated server or cloud hosting is ideal over shared.

After migrating to a beefier setup, the 502 errors should subside as your site can now handle the increased demand.
7. Increase the WordPress Memory Limit
By default, WordPress allocates 32MB of memory to PHP. For busier sites with many plugins, this may not be enough, leading to 502 errors as processes exceed the limit.
To increase WordPress‘ memory limit:
- Access your site‘s root folder via FTP/SFTP
- Locate the wp-config.php file and download a copy
- Open wp-config.php in a text editor
- Add this line before "Happy publishing": define( ‘WP_MEMORY_LIMIT‘, ‘64M‘ );
- Save the file and re-upload to your server
This doubles WordPress‘ memory limit to 64MB, which should be enough in most cases. For very resource-heavy sites, you may need to go higher (128M, 256M etc).
Be aware that your host may have their own memory limits that override this. Check with them if increasing WP_MEMORY_LIMIT doesn‘t resolve the 502.
8. Debug a Specific Plugin or Theme Issue
If you suspect a certain plugin or theme may be causing the 502 errors, you can enable WordPress‘ built-in debug mode to identify the culprit.
Add these lines to your wp-config.php file right before "Happy publishing":
define( ‘WP_DEBUG‘, true );
define( ‘WP_DEBUG_LOG‘, true );
define( ‘WP_DEBUG_DISPLAY‘, false );
This enables WordPress to log detailed PHP errors to a debug.log file in your /wp-content/ directory. Refresh your site a few times to trigger the 502, then download and open debug.log.
Look for any plugin or theme functions throwing PHP fatal errors or memory exhaustion warnings. These indicate likely causes of the 502. You may need to deactivate the plugin/theme or find an alternative.
9. Reinstall a Fresh Copy of WordPress Core
If your WordPress core files somehow got corrupted or infected with malware, it could cause 502 errors as malicious code interferes with normal functions.
Download a fresh copy of WordPress from WordPress.org. Unzip it and delete the wp-content folder (you don‘t want to overwrite your content, plugins or themes).
Upload the fresh files to your site‘s root directory via FTP/SFTP, overwriting the old ones. This will restore your WordPress core to pristine condition without affecting your content.
Then run the update process again from your admin dashboard. The new untainted core files may resolve the 502 issues.
10. Consider Switching to a New WordPress Host
If your host‘s servers seem to be the crux of the problem and they‘re unable to resolve it, you may need to consider migrating to a new host altogether.
Recurring downtime and 502 errors are indicators of deeper server instability and lack of maintenance. These issues will keep cropping up and hurting your site‘s performance.
Research other managed WordPress hosts with modern infrastructure, proactive security, and expert 24/7 support. They may cost a bit more but the peace of mind and reliability is worth it.
Use a WordPress migration plugin or professional service to carefully move your site to the new host. After migrating, the 502 errors should be gone and you‘ll enjoy significantly better hosting.
Proactive Ways to Prevent 502 Errors on Your WordPress Site
Now that your site is out of 502 error purgatory, let‘s review some best practices to avoid future recurrences:
- Choose a reputable WordPress hosting provider with modern, well-maintained infrastructure. Avoid cheap shared hosting.
- Keep WordPress core, plugins and themes updated to the latest versions. Set up auto-updates if possible.
- Use a 24/7 uptime monitoring service like Uptime Robot or Pingdom to catch 502 errors and downtime early.
- Regularly back up your WordPress site so you can restore quickly in case of emergency. Store backups offsite.
- Implement caching, a CDN, and an optimized WordPress hosting stack to handle high traffic loads.
- Carefully vet new plugins and themes for quality and compatibility before installing on a live production site.
By being proactive in these areas, you‘ll greatly reduce the chance of running into 502 bad gateway errors and increase your WordPress site‘s stability.
Wrapping Up
Dealing with 502 errors is never fun but working through them methodically often leads to a resolution. The key is isolating each potential cause and testing solutions one by one.
If you‘re uncomfortable with troubleshooting or hit a wall, don‘t hesitate to contact your hosting support or a qualified WordPress maintenance specialist. They can do a deeper technical dive to pinpoint the issue.
This guide covered 10 common solutions to the 502 bad gateway error in WordPress. Hopefully one of them did the trick for you! Remember, proactive measures like regular updates, monitoring, and quality hosting prevent many 502 errors from happening at all.
For further reading, check out the additional resources below:
- Official WordPress guide to debugging
- How to update WordPress core, plugins and themes
- Official WordPress guide to backing up your site
The important thing is getting your WordPress site back online ASAP. Follow this guide closely and you‘ll conquer those 502 errors for good!
