Skip to content
SazM Fixed-price website fixes
Find a service
Where can I help?

Use arrow keys to browse, Enter to open, and Escape to close.

11 destinations

Client Login Get a fix →

Bug Fixing · 5 min read

WordPress 502 Bad Gateway (nginx, PHP-FPM): Affordable $99 Fix

Fix WordPress and WooCommerce 502 Bad Gateway errors on nginx: PHP-FPM socket, crashes, pm.max_children and timeouts, with a $99 fixed-price option.

Summary

Visitors see 502 Bad Gateway from nginx, usually on WooCommerce admin pages, product saves, checkout or a heavy plugin screen, while simple pages still load. It often appears at random, or right after a PHP upgrade (for example to PHP 8.4), a plugin update or a traffic spike. The cause is almost never WordPress itself: nginx asked PHP-FPM for a response and got none.

This guide gives you the log-first isolation steps. If you would rather hand it over, SazM fixes a WordPress or WooCommerce 502 for an affordable, fixed $99, delivered within 48 hours, entirely in writing.

Where the Error Lives

Check the nginx and PHP-FPM logs before touching any setting:

/var/log/nginx/error.log
/var/log/php8.3-fpm.log          # name matches your PHP version
/var/log/php8.3-fpm-slow.log     # only if request_slowlog_timeout is set

Typical lines and what they point to:

connect() to unix:/run/php/php8.3-fpm.sock failed (2: No such file or directory)
  -> PHP-FPM is down, or the socket path in the nginx vhost does not match the pool

upstream prematurely closed connection while reading response header from upstream
  -> a PHP-FPM child crashed (segfault, memory limit, killed by the OOM killer)

upstream timed out (110: Connection timed out) while reading response header from upstream
  -> PHP ran longer than fastcgi_read_timeout (often a slow query or an outbound API call)

WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
  -> every worker is busy, so new requests queue and fail

Note: a timeout usually returns 504, while a crashed or unreachable PHP-FPM returns 502. Both come from the same place.

Quick Fix Breakdown (DIY)

  • Is PHP-FPM running and is the socket there?
systemctl status php8.3-fpm
ls -l /run/php/
sudo nginx -t
grep -R "fastcgi_pass" /etc/nginx/sites-enabled/

The fastcgi_pass value must match the listen line in /etc/php/8.3/fpm/pool.d/www.conf.

  • Look for crashes and the OOM killer.
journalctl -u php8.3-fpm --since "1 hour ago"
dmesg -T | grep -i -E "killed process|out of memory"

"Killed process ... php-fpm" means the server ran out of RAM. Lower pm.max_children or add memory; do not simply raise it.

  • Size the pool to your RAM. Measure one worker, then divide:
ps --no-headers -o rss -C php-fpm8.3 | awk '{s+=$1; n++} END {print s/n/1024 " MB average"}'
; /etc/php/8.3/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 12
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
request_terminate_timeout = 120s
request_slowlog_timeout = 10s
slowlog = /var/log/php8.3-fpm-slow.log
  • Give slow admin requests enough time (only after you know why they are slow):
location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_read_timeout 120s;
    include fastcgi_params;
}
  • Rule out a PHP version or extension problem. If 502s began right after a PHP upgrade, check the slow log and the FPM log for a segfault line, then compare with the previous PHP version on a staging copy. Some reports tie random 502s on WooCommerce admin pages to a specific PHP-FPM version or an extension such as an opcache or object-cache module.
  • Isolate the plugin on staging, not live.
wp plugin list --status=active
wp plugin deactivate --all --exclude=woocommerce
# test the failing screen, then re-enable one at a time
wp plugin activate <slug>
  • Reload cleanly after any change.
sudo php-fpm8.3 -t && sudo systemctl reload php8.3-fpm
sudo nginx -t && sudo systemctl reload nginx

If the log lines do not point to one cause within an hour, stop. Random restarts hide the cause and it returns under load.

Hand It Over: $99 Fixed, Within 48 Hours

A 502 gets passed between the host, the plugin author and the theme vendor because each log only shows one side. One developer who reads the nginx log, the FPM log and the slow log together, reproduces it on staging and fixes the root cause ends that.

What you get for $99:

  • A fixed price agreed before work starts. One 502 problem, one flat fee, no hourly meter.
  • Delivery within 48 hours of access, verified on staging before anything touches your live site.
  • Fully written, fully async. You send the URL, the screen that fails and when it started. Questions, progress and proof come back in writing, so there are no calls, meetings or project managers and your time zone does not matter.
  • Written proof it works: the root cause in plain language, the exact config or code changed, before and after log evidence and a rollback note.
  • Money-back guarantee if the agreed root cause cannot be resolved.
  • Safe access only: a separate admin or SSH account, staging first. Never send passwords through the inquiry form.

Behind it: 20+ years in production (since Oct 2006) and 100+ projects in the portfolio.

Get your 502 fixed for $99 → · Queue an urgent fix · See past projects

If the site is also slow under load, the $199 Core Web Vitals fix can be done in the same window.

See also: WordPress "Allowed memory size exhausted" and Cloudflare Error 522 if the failure is between Cloudflare and your server.

Frequently Asked Questions

What causes a 502 Bad Gateway on WordPress with nginx?

nginx could not get a valid response from PHP-FPM. The usual causes are PHP-FPM not running, a wrong socket path, workers crashing or being killed for memory, or all workers being busy. The nginx error log line tells you which.

Why does WooCommerce admin return 502 but the front end works?

Admin screens, product saves and imports run longer and use more memory than cached front-end pages, so they hit worker memory limits, timeouts or a crashing extension first.

How do I fix "upstream prematurely closed connection"?

A PHP-FPM child died while handling the request. Check journalctl and dmesg for a memory kill or segfault, size pm.max_children to available RAM and test the failing screen with plugins disabled on staging.

How much does it cost to fix a WordPress 502 Bad Gateway?

SazM fixes one 502 problem for an affordable, fixed $99, delivered within 48 hours, with a money-back guarantee if the agreed root cause cannot be resolved. Typical agency hourly rates are higher and open-ended, and very low marketplace gig prices rarely include root-cause diagnosis, staging tests or a guarantee.

Do I need a call to explain the 502?

No. Send the URL, the failing screen, when it started and what changed. A written report with the log lines is more precise than a call.

// SazM ENGINEERING DISPATCH · PRODUCTION REMEDIATION

Senior Engineering Without Agency Overhead

// TRACK A · FIXED-PRICE FIXES (48H SLA)

Single Urgent or Speed Fix

Immediate code-level fixes with zero discovery calls. Emergency root-cause patch within 48 hours for $99, or full Core Web Vitals & speed remediation with before/after audit for $199. 100% money back if the agreed root cause cannot be fixed.

Running WordPress or WooCommerce? The WordPress care plan keeps your site updated, hardened, backed up daily, and monitored for $49/mo.

// TRACK B · SENIOR RETAINER & BUILDS

Monthly Plan or Custom Scope

Direct senior-level capacity embedded in your stack. Dedicated monthly engineering ($999/mo, 1 active task at a time, 24–48h PR delivery, pause or cancel anytime), or fixed-scope architectural milestones delivered within a 24h written quote.

✓ 20+ years engineering ✓ 100+ projects in the portfolio ✓ Fixes within 48 hours ✓ 100% money back if not fixed
1 Active Task at a Time
Requests are completed one by one in your priority order. As soon as an active task is shipped, tested, and approved, work starts immediately on your next task within our 24–48h SLA.
48h Emergency SLA
Clock starts as soon as site access details are provided. Delivered with full backup taken first, isolated staging testing, and 100% money back if not fixed.
WordPress Care Plan Scope
Weekly core and plugin updates pre-tested in staging, daily offsite encrypted backups, 24/7 uptime monitoring, and proactive security patching.
Pay Nothing Upfront
Zero upfront payment or credit card required. A 20-Year Senior Engineer diagnoses your issue, reproduces it on isolated staging, and deploys the fix. You only pay once you verify the staging reproduction or production fix.