A 502 Bad Gateway error in WordPress means the server received an invalid response from an upstream server — usually PHP-FPM crashing or being overwhelmed, Nginx misconfiguration, or a gateway timeout from a slow PHP script.
Most common causes we diagnose:
Systematic, fast, and safe process:
Run: systemctl status php-fpm and check /var/log/php-fpm/error.log for "server reached pm.max_children" or crash messages.
In nginx.conf or site config, add: fastcgi_read_timeout 300; proxy_read_timeout 300; fastcgi_connect_timeout 300;
Edit /etc/php-fpm.d/www.conf: increase pm.max_children to handle more concurrent requests. For 2GB RAM: set to 40-60.
Our WordPress expert responds in minutes.
502 Bad Gateway means the server got an invalid response from upstream (PHP-FPM crashed or reset the connection). 504 Gateway Timeout means the upstream took too long to respond (PHP script timeout).
Intermittent 502s usually mean your PHP-FPM pool is occasionally running out of workers during traffic spikes — a scalability issue, not a code bug.
500: server error in your application. 502: bad gateway — the proxy got an invalid response from the upstream. 503: service unavailable. 504: gateway timeout — the proxy waited too long for the upstream. 502 and 504 are most common with WordPress/Nginx setups.
Heavy pages (admin lists with many records, importing data, generating reports) take longer than your PHP-FPM timeout (default 30 seconds). The proxy times out waiting and returns 502. We bump fastcgi timeouts and optimize the slow query.
Yes. If nginx is configured to talk to PHP-FPM on a wrong socket path (eg /var/run/php-fpm.sock that no longer exists), every request returns 502. We verify the actual PHP-FPM listen address matches nginx's fastcgi_pass.
Common causes: PHP segmentation fault (rare, usually from a buggy extension), PHP-FPM hitting pm.max_children limit and refusing connections, or PHP-FPM running out of memory and being killed by OOM killer.
Edit /etc/php/8.x/fpm/pool.d/www.conf and increase pm.max_children based on your server's RAM. Each PHP worker typically needs 64-128MB. Server with 8GB RAM and 100MB per worker = 60-70 workers safe.
Maybe — but it usually moves the problem rather than solves it. Apache mod_php is simpler but uses more memory per request. We diagnose the real bottleneck first instead of switching architectures.
Yes. PHP waiting for MySQL exceeds the proxy timeout. We identify slow queries via slow_query_log, add indexes, and either optimize the query or implement caching.
Background processes can spike resource usage: cron jobs, backup plugins, image regeneration. We check the timing of 502 occurrences against scheduled tasks to find the trigger.
Cloudflare doesn't cache 5xx errors by default, but if you have aggressive cache rules including 5xx, yes. We always set proper cache rules excluding error responses.
Look at your access logs vs error logs: if the 502 appears in error log AND access log, it's from your nginx/Apache. If only in access log with status=502, it's likely from a CDN or load balancer above. Trace the layers carefully.
Yes. Shared hosting overloads, DDOS attacks affecting the data center, or backbone issues can cause sporadic 502s. We can identify these via uptime monitoring patterns matching the host's status page.
Often yes. PHP 8.x has lower memory usage and faster execution, reducing the chance of timeouts and worker exhaustion. We test compatibility before recommending PHP version changes.
We set up: uptime monitoring (UptimeRobot, BetterStack) with HTTP status alerts, log parsing with alerts on 502 frequency, and Application Performance Monitoring (New Relic, Datadog) for upstream health.
WordPress site suddenly slow? We diagnose performance bottlenecks and restore your speed.
Response in minutes. No data loss. No diagnosis charge.
wpfix.blimx.com