502 Bad Gateway in WordPress – causes and solutions

A 502 Bad Gateway error is usually temporary, but you still want to know the cause fast and get your site back online.

A “502 Bad Gateway” error on your WordPress site can be alarming. Fortunately, this server error is usually temporary and fixable. In this article I explain what the 502 Bad Gateway message means, the most common causes, and—most importantly—how you can resolve it yourself. The goal is to get your site back online quickly without panic.

What is a 502 Bad Gateway error?

A 502 Bad Gateway is an HTTP status code that indicates something goes wrong between two servers. In short: a server acting as a gateway for your site receives an invalid response or no response from the origin server (the server where your website runs). Instead of showing your page, the gateway server returns “502 Bad Gateway” to your browser.

In practice this often happens during a temporary communication issue. The server couldn’t process your request correctly or a timeout occurred. The result is that your site doesn’t load and you see a 502 error page. This can happen on any website—from small blogs to large services—and it doesn’t mean your site is permanently broken. Below I explain why this error happens and how to fix it.

Common causes of a 502 error (and solutions)

A 502 Bad Gateway is caused by communication issues between servers. But what creates those issues? Below are the most common causes on WordPress sites, each with a practical fix. Go through them one by one; with a bit of luck your site will be back up quickly.

1. Temporary server glitch

Cause: A 502 error is often just a temporary hiccup or short overload. You may have had a sudden traffic spike, the server restarted, or your hosting provider is doing brief maintenance. In that case the gateway gets no valid response, but it usually recovers quickly.

Solution: Often you don’t need to do much. Wait 30–60 seconds and refresh the page (press F5 or click the reload button). In many cases the error disappears on its own. You can also check via an external service like “Down for Everyone or Just Me” to see if your site is down for others too. If the error persists after several minutes and refreshes, move on to the next causes below.

2. Error in .htaccess or PHP configuration

Cause: A bad server configuration can also lead to a 502. On Apache servers, WordPress relies heavily on the .htaccess file. Errors in that file—like a bad rewrite rule or a typo—can prevent requests from reaching the backend and result in a 502. Certain PHP settings (like an overly strict memory limit, the wrong PHP version, or a misconfigured PHP-FPM setup) can also disrupt communication between server processes.

Solution: Check recent changes. Did you manually add rules to .htaccess or install a plugin that modified it? Test whether .htaccess is the issue by renaming it temporarily. Via FTP or your hosting file manager, rename .htaccess in public_html to something like htaccess_old. Then try loading the site. If it works, you know .htaccess was the problem. Restore the default WordPress .htaccess (or let WordPress regenerate it via the Permalinks settings) and add any custom rules one by one to find the culprit.

Also review your PHP settings. In many hosting panels you can change the PHP version and configuration. Make sure you’re running a supported PHP version and that settings like memory_limit aren’t too low. Increase limits (like max_execution_time) within reasonable bounds and test again. If you’re stuck, hosting support can often tell you if configuration errors are causing the 502.

3. Issues with caching or a reverse proxy (e.g., Cloudflare)

Cause: If you use a CDN like Cloudflare or another caching/proxy service, the 502 can originate there. A service like Cloudflare sits between the visitor and your server to speed up content and filter traffic. If that layer has problems or doesn’t get a proper response from your server, visitors see a 502 Bad Gateway page. Cloudflare even has two types of 502 messages: one when Cloudflare itself is down and one when your origin server doesn’t respond properly. Either way, the visitor sees “502 Bad Gateway,” sometimes with a subtle hint like “Cloudflare” or “Host Error.”

Solution: Check the status of your CDN or caching service. For Cloudflare, use the Cloudflare Status page to see if there are outages. If you see a Cloudflare-branded error page, the problem may be on their side—wait a bit or contact their support if it drags on.

If the issue doesn’t clearly point to the CDN, focus on your server. A useful step is to temporarily disable or bypass the CDN. In Cloudflare you can set DNS records to “Direct” (toggle the orange cloud off) or enable “Development Mode” so traffic goes straight to your server. If the site loads without the 502, the issue is in the CDN interaction. Next steps include purging caches (both on your server and on the CDN) and reviewing firewall, SSL, and DNS settings in the CDN. Only re-enable the CDN when everything looks correct.

Do you use a caching plugin or proxy on your own server (e.g., Varnish or a WordPress caching plugin with Nginx)? That can also be a factor. Try purging the cache or temporarily disabling the plugin to see if that changes anything. A misconfigured caching layer can cause invalid responses that the gateway treats as “bad.”

4. Conflicting plugins or themes

Cause: In WordPress, 502 errors can also come from plugin or theme problems. Poorly written or outdated plugins can conflict or throw errors that cause the server to hang. For example, two plugins that don’t work well together can end up in an infinite loop or heavy query, so the server stops responding. A broken or incompatible theme can cause similar issues. In these cases the server stops executing PHP scripts and you get a 502.

Solution: Test whether a plugin or theme is responsible by temporarily disabling them.

Disable plugins: log in to your WordPress dashboard and go to Plugins. Deactivate all plugins at once (select all, choose “Deactivate” from the bulk menu, and confirm). Then load your site. If the 502 disappears, a plugin is the culprit. Reactivate plugins one by one, refreshing the site each time. When the 502 returns, you’ve found the conflicting plugin. Update or replace it, or contact the developer for a fix.

No access to wp-admin? If the error blocks the dashboard, disable plugins via FTP or your hosting panel. Go to the wp-content folder and rename the plugins directory to something like plugins_off. That deactivates all plugins. Test the site; if it works, rename the folder back to plugins and then rename individual plugin folders one by one until the error returns.

Check the theme: if plugins don’t seem to be the issue, do the same for your theme. Switch to a default WordPress theme (e.g., Twenty Twenty-Three) via the dashboard, or rename your current theme folder via FTP (wp-content/themes). If a theme issue caused the error, the site should load with a default theme. Then update or replace the original theme.

Keep both plugins and themes up to date. Many 502 issues are caused by outdated code or bugs already fixed in later updates.

5. Overload or timeouts due to PHP workers

Cause: Another common reason for 502 errors is server overload or time limits. WordPress runs on PHP; every visitor triggers PHP processes (often called “PHP workers”) to generate pages. If your hosting account doesn’t have enough PHP workers to handle requests, or if certain processes run so long that they exceed limits, the server starts cutting off requests. Instead of a page you see a 502 or a related timeout error (sometimes a 504 Gateway Timeout). This is especially common during traffic spikes, heavy scripts, or inefficient plugins.

Solution: There are two angles here: optimize the site, and increase server capacity. Practical steps to try right away:

  • Optimize your site: check for plugins or features that use a lot of resources. Caching static pages (with a caching plugin) can drastically reduce PHP requests. Optimize database queries and disable unnecessary plugins. Use your hosting dashboard to monitor CPU and memory usage to see if something keeps hitting the ceiling.
  • Increase server resources if possible: many hosting plans (especially shared hosting) have limits on concurrent PHP processes and memory. If your site grows or gets a lot of simultaneous visitors, you can hit those limits. Consider upgrading your hosting plan so you get more PHP workers and CPU/RAM. On a VPS or dedicated server you can increase PHP-FPM processes. Note that more resources usually cost more, so it’s a balance between budget and performance. But if 502 errors become frequent under load, scaling up is often unavoidable.
  • Check long-running processes: sometimes a specific action is the culprit, like a daily cron job, backup process, or import script that runs too long. Check error logs or use monitoring tools (e.g., the WordPress plugin Query Monitor or a tool like New Relic) to see if there are errors or timeouts around the 502. If a PHP error or script keeps hanging, fix it or disable that functionality temporarily.

In short, avoid overheating your server. By making your site more efficient and ensuring enough server capacity, you significantly reduce the chance of 502 Bad Gateway errors.

Conclusion

A 502 Bad Gateway error is frustrating, but usually temporary and fixable. I’ve covered common causes—from small server hiccups to configuration errors and overloaded servers—and what you can do in each case. In most situations, the tips above are enough to get your WordPress site back online quickly.

Want this to stop being your problem?

If outages or errors keep repeating, the fix is often consistency: updates, backups and monitoring that don’t get skipped.

See managed WordPress hosting