Nginx handles thousands of connections per worker without effort. If your site is slow, it is nearly always waiting on PHP or the database behind it. Raising these numbers moves the queue, it does not shorten it.
The two numbers
worker_processes auto; # one per CPU core - leave it
events {
worker_connections 1024; # per worker
multi_accept on;
}
auto matches the core count, which is the right answer on every machine this side of a very unusual one. Total capacity is workers multiplied by connections, and a browser opening several connections to one site counts several times.
The error that means raise it
grep "worker_connections are not enough" /var/log/nginx/error.log
That line, and only that line, is a reason to raise the number. Without it, the limit is not what you are hitting.
What is usually the real limit
- PHP-FPM children - the queue is there, not in Nginx. See sizing a PHP-FPM pool.
- Database connections - see too many connections.
- Open files - the worker hits the system limit long before it hits its own.
# the one worth raising, with the connections
worker_rlimit_nofile 65535;
Reload, never restart, to apply
sudo nginx -t && sudo systemctl reload nginx
A reload starts new workers for new connections and lets the old ones finish. A restart drops what is in flight, which on a busy site is a visible error for somebody.