The web server serves static files itself and passes PHP requests to PHP-FPM via a Unix socket or TCP port. Each pool has its own settings, user and limits, which keeps several applications cleanly separated.
The key setting is pm.max_children: it caps how many requests run at the same time. Too low and requests queue up (log: server reached pm.max_children setting). Too high and memory runs out until the OOM killer starts terminating processes.
Rule of thumb: RAM available for PHP divided by the average memory per process. If PHP-FPM is down or the socket path is wrong, nginx answers 502; for scripts running too long, 504.
Example
grep -E '^pm' /etc/php/8.3/fpm/pool.d/www.conf