Key Takeaways (BLUF)
Bottom Line Up Front: A 502 Bad Gateway error on a WordPress site almost always means your Nginx web server is running but cannot communicate with the PHP-FPM process that executes WordPress. This is distinct from a 503 (server overloaded) or 500 (PHP crashed mid-execution). The fix is usually restarting PHP-FPM or adjusting its process pool limits. WakeMetric detects 502 errors from outside your server and alerts you within minutes so you can fix the issue before visitors experience it.
What Causes a WordPress 502 Bad Gateway Error?
HTTP 502 means a server acting as a gateway received an invalid response from an upstream server. In the WordPress stack, this means your web server (Nginx or a Cloudflare proxy) received a bad or no response from the PHP-FPM process that handles PHP execution.
- PHP-FPM crashed or stopped: The PHP-FPM service terminated unexpectedly due to a memory error, a PHP fatal error that killed the process, or an OS-level OOM (out of memory) kill
- PHP-FPM process pool exhausted: All available PHP-FPM worker processes are busy handling other requests — new requests get a 502 instead of queuing
- PHP-FPM socket misconfiguration: After a server migration or PHP version upgrade, the Nginx configuration points to a socket path that no longer exists
- Cloudflare returning 502: If your site is behind Cloudflare, a 502 from Cloudflare means Cloudflare can reach the internet but your origin server returned an invalid response
How to Fix a WordPress 502 Bad Gateway Error
Restart PHP-FPM (fastest fix): On a VPS or dedicated server, run: sudo systemctl restart php8.2-fpm (replace 8.2 with your PHP version). This immediately restores PHP processing and clears the 502 in most cases.
Check PHP-FPM process pool limits: Open your PHP-FPM pool configuration (typically at /etc/php/8.2/fpm/pool.d/www.conf). Increase pm.max_children if you are on pm = static, or adjust pm.max_spare_servers and pm.max_children if on pm = dynamic. Too few worker processes cause pool exhaustion during traffic spikes.
Check for socket path mismatches: Compare the fastcgi_pass value in your Nginx site configuration with the listen = value in your PHP-FPM pool config. If Nginx is pointing to /run/php/php8.2-fpm.sock but the socket is at /run/php8.2-fpm.sock, the 502 is caused by this path mismatch.
For Cloudflare 502 errors: Check your origin server's status independently. If the origin is healthy, the issue may be a Cloudflare configuration problem — check your Cloudflare dashboard for any active incidents.
Monitoring WordPress for 502 Errors with WakeMetric
WakeMetric detects 502 errors the same way it detects any downtime — by receiving a non-2xx HTTP response from its external checks. When your site returns a 502, the monitoring nodes confirm it from multiple global regions and send an alert to your configured email address.
Install WakeMetric from WordPress.org (Plugins → Add New → search "WakeMetric"), connect with your alert email, and monitoring begins immediately. You will receive an alert within 15 minutes of a 502 appearing, plus a recovery confirmation when PHP-FPM is restored.
Frequently Asked Questions
What is the difference between WordPress 502 and 503?
A 502 Bad Gateway means your web server (Nginx) could not get a valid response from PHP-FPM — PHP is not responding at all. A 503 Service Unavailable means the server is temporarily unable to handle requests — usually because it is overloaded or in maintenance mode, but PHP-FPM itself is still running. In practice: 502 usually means restart PHP-FPM; 503 usually means reduce server load or check for maintenance mode.
I get 502 errors only during high traffic periods. How do I fix this permanently?
Intermittent 502 during high traffic is a PHP-FPM pool exhaustion problem. Your server does not have enough PHP-FPM worker processes to handle peak concurrent requests. Solutions: increase pm.max_children in your PHP-FPM pool configuration, implement a WordPress caching plugin (LiteSpeed Cache, WP Rocket) to serve cached pages without invoking PHP, or upgrade to a higher-capacity hosting plan.
Conclusion
WordPress 502 Bad Gateway errors are frustrating precisely because they are often intermittent — appearing during traffic spikes and resolving on their own, leaving you uncertain whether anything needs fixing. WakeMetric's external monitoring catches every 502 occurrence and logs the timestamp, giving you a clear record of when and how often it happens. Install WakeMetric free and never miss a 502 again.