Logo
WP Fix by Blimx
⏱️correção wordpress 502 bad gateway

WordPress 502 Bad Gateway / Timeout Fix

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.

⚡ Response in minutes🔒 No data loss🛠️ WP-CLI + FTP + SSH✅ Same-day fix🌎 Remote — works anywhere

Why Does This Error Happen?

Most common causes we diagnose:

PHP-FPM process pool exhausted — no available workers to handle requests
Nginx upstream timeout set too low for slow PHP scripts
Long-running PHP script exceeding fastcgi_read_timeout limit
Redis or Memcached connection failure breaking WordPress object cache
Sudden traffic spike overwhelming the PHP worker process pool

How We Fix It — Step by Step

Systematic, fast, and safe process:

1

Check PHP-FPM status and logs

Run: systemctl status php-fpm and check /var/log/php-fpm/error.log for "server reached pm.max_children" or crash messages.

2

Increase Nginx timeout values

In nginx.conf or site config, add: fastcgi_read_timeout 300; proxy_read_timeout 300; fastcgi_connect_timeout 300;

3

Scale PHP-FPM pool

Edit /etc/php-fpm.d/www.conf: increase pm.max_children to handle more concurrent requests. For 2GB RAM: set to 40-60.

Dealing with this right now?

Our WordPress expert responds in minutes.

Frequently Asked Questions

QWhat is the difference between 502 and 504 in WordPress?

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).

QWhy do I get 502 only sometimes and not always?

Intermittent 502s usually mean your PHP-FPM pool is occasionally running out of workers during traffic spikes — a scalability issue, not a code bug.

QWhat is the actual difference between 502, 503, 504, and 500?

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.

QWhy am I getting 502 only on heavy admin pages?

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.

QCan a wrong nginx fastcgi_pass cause 502?

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.

QWhy does PHP-FPM crash and cause 502?

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.

QHow do I increase PHP-FPM workers to prevent 502?

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.

QWill switching from FastCGI to Apache module fix 502?

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.

QCan a slow database query cause 502?

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.

QWhy does 502 happen randomly even with low traffic?

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.

QWill Cloudflare cache 502 responses and keep showing them?

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.

QHow do I check if 502 is from upstream or from the proxy itself?

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.

QCan a hosting provider's network issue cause 502 at random?

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.

QWill moving to a different PHP version reduce 502?

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.

QHow can I monitor for 502 errors automatically?

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.

Full Service: WordPress Speed Recovery

WordPress site suddenly slow? We diagnose performance bottlenecks and restore your speed.

🚨

WordPress Emergency Support

Response in minutes. No data loss. No diagnosis charge.

wpfix.blimx.com