Home/Blog/502 Bad Gateway in WordPress: 7 Fixes (2026)

502 Bad Gateway in WordPress: 7 Fixes (2026)

Two server racks with a broken glowing connection bridge between them, concept of bad gateway failure

A 502 Bad Gateway error means the server acting as a gateway (often Nginx, a CDN like Cloudflare, or a proxy) got an invalid response from the server behind it that actually runs WordPress. Your site is up at some level, but the pieces are not talking to each other. The 502 bad gateway WordPress fix is usually a server-side issue — crashed PHP workers, an overloaded server, or a CDN caching a bad response — and this 2026 guide walks you through seven proven fixes.

What Causes the 502 Bad Gateway Error in WordPress?

The 502 is a communication failure between two servers: the front door (Nginx/CDN/proxy) knocked, and nobody valid answered. The most common causes are:

  • PHP-FPM crashed or is overloaded: The number-one cause on Nginx servers. PHP-FPM manages the pool of PHP worker processes that run WordPress. When all workers are busy, stuck, or crashed, Nginx gets no valid response and returns 502.
  • Server resource exhaustion: CPU or RAM maxed out — from a traffic spike, a heavy plugin, or a runaway cron job — so PHP-FPM or MySQL gets killed by the system (the OOM killer).
  • CDN caching a bad response: Cloudflare or another CDN cached a 502 from a brief outage and keeps serving it even after the origin recovered.
  • Plugin or theme fatal error: A PHP fatal error mid-response produces an invalid response that the gateway reports as 502.
  • Database problems: MySQL crashing or refusing connections makes PHP die mid-response — especially on shared hosting during peak traffic.
  • Wrong PHP-FPM socket in Nginx config: Nginx points to a PHP version/socket that does not exist (often right after a PHP upgrade).
  • Firewall blocking the proxy: A server firewall or security plugin blocking communication between the proxy/CDN and the origin server.

How to Fix the 502 Bad Gateway Error in WordPress

If the 502 is site-wide and you cannot reach wp-admin, this is almost certainly infrastructure-level — start at the server, not the dashboard:

  1. Reload and rule out a transient spike. Hit Ctrl+Shift+R (hard refresh). If it was a momentary overload, the site may already be back. If the 502 persists, continue.
  2. Purge the CDN cache. In Cloudflare, go to Caching → Configuration → Purge Everything. A CDN serving a cached 502 from a brief outage is a classic false alarm. Also check Cloudflare’s status — if Cloudflare itself is having issues, wait it out. More CDN troubleshooting is on the KamiWeb blog.
  3. Restart PHP-FPM (VPS/dedicated). Via SSH: sudo systemctl restart php8.3-fpm (match your PHP version), then restart Nginx: sudo service nginx restart. On managed hosting, look for a “restart PHP” or “Manage Services” option in your panel. This clears stuck workers and is the single most effective fix.

Gateway arch reconnecting two server towers with a restored glowing bridge, concept of restoring server communication

  1. Check server resources. Look at CPU/RAM usage in your hosting panel (or run free -h via SSH). If RAM is maxed out, find the hog: disable heavy plugins, kill stuck cron jobs, and consider upgrading the plan. Check dmesg | grep -i "out of memory" to see if the system killed PHP-FPM or MySQL.
  2. Read the error logs. Check /var/log/nginx/error.log for phrases like “upstream sent too big header” or “connection refused” — the smoking gun that tells you exactly which backend failed. Also check the PHP-FPM log and enable WordPress debug logging (WP_DEBUG_LOG) to catch plugin/theme fatals that produce invalid responses.
  3. Deactivate plugins via FTP. Rename wp-content/plugins to plugins.deactivated. If the 502 clears, a plugin is crashing PHP mid-response — reactivate one by one to find it, then replace it with a reliable option from our free WordPress plugins collection.
  4. Contact your hosting provider. On shared hosting you cannot restart PHP-FPM yourself — report the 502 with timestamps and ask them to check PHP-FPM status, worker pool size, and server load. If 502s recur under normal traffic, ask about increasing the PHP-FPM worker count (pm.max_children) or moving to a plan with more headroom. Keep everyday site utilities handy via the KamiWeb free tools.

Conclusion

The 502 Bad Gateway is the front server telling you the back server failed: restart PHP-FPM, purge the CDN cache, check resources and logs, and rule out plugin fatals. Short 502 blips will not hurt your SEO, but if they persist for more than a day, search engines start de-indexing pages — so act fast. For more free resources, start at the KamiWeb homepage.