## 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:

```text
/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:

```text
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?**

```bash
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.**

```bash
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:

```bash
ps --no-headers -o rss -C php-fpm8.3 | awk '{s+=$1; n++} END {print s/n/1024 " MB average"}'
```

```ini
; /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):

```nginx
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.**

```bash
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.**

```bash
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 →](/bug-fix-services)** · [Queue an urgent fix](/checkout/emergency) · [See past projects](/projects)

If the site is also slow under load, the $199 [Core Web Vitals fix](/articles/core-web-vitals-inp-lcp-remediation) can be done in the same window.

See also: [WordPress "Allowed memory size exhausted"](/articles/wordpress-allowed-memory-size-exhausted-fix) and [Cloudflare Error 522](/articles/cloudflare-error-522-connection-timed-out-fix) 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.
