Open the Nginx config on almost any VPS and you will find a harmless-looking line: worker_connections 1024;. Most people ignore it until their site starts throwing 500 errors during a traffic spike. Nginx worker connections is the setting that caps how many simultaneous connections a single Nginx worker process can handle. Set it too low and real visitors get turned away; set it too high and you waste memory or hit the operating system limits underneath it.
What Nginx Worker Connections Actually Controls
Every Nginx worker process handles many connections at once using an event loop. The worker_connections directive, inside the events block, sets the maximum simultaneous connections one worker process can open. It does not limit the whole server: the server total is roughly worker processes multiplied by worker connections, minus the connections Nginx keeps for itself.
A connection is one open socket between Nginx and something else: usually a visitor’s browser, but also an upstream server such as PHP-FPM. A single page load often opens several at once, because the browser fetches images, stylesheets, and scripts in parallel, so connections always outnumber visitors.
events {
worker_connections 1024;
}
With one worker process per CPU core, a 2-core VPS with worker_connections 1024 can hold about 2,048 simultaneous connections, and a 4-core machine about 4,096. The exact total is a little lower because Nginx reserves some connections for itself, but the multiplication is the right way to think about it.
Nginx Worker Connections vs Worker Processes
People often confuse these two settings, and they do different jobs. The worker_processes directive decides how many Nginx worker processes run. The worker_connections setting decides how many connections each of those processes can juggle. Raise the first and you get more processes working in parallel; raise the second and each process can hold more connections open at once.
The standard starting point is worker_processes auto;, which creates one worker per CPU core. That is the right default for most VPS setups because Nginx workers spend most of their time waiting on the network, not burning CPU. Once that is set, worker connections is the dial you turn to handle more simultaneous visitors.
Each connection costs memory: a few kilobytes for the connection state plus buffers Nginx allocates. A huge number on a small VPS does not make the server faster; it just lets Nginx accept more connections than the machine can serve, and the extras sit in a queue while response times climb. Pick a number your server can genuinely support.
How Many Connections Does One Visitor Use?
There is no fixed answer, which is why the right number varies so much between sites. A visitor on a modern browser typically opens between 2 and 6 connections to load a page, and HTTP/2 changes the picture further by multiplexing many requests over a single connection. A heavy WordPress page with dozens of assets can easily use six or more connections at the moment of loading, while a plain HTML page might use one or two.
Keepalives add to the count. With keepalive_timeout enabled, a browser holds a connection open after the page loads, and those idle connections still count against your worker connections limit. Reverse proxies add another layer: when Nginx sits in front of PHP-FPM, each visitor connection can spawn a matching upstream connection, so the limit should be at least double what you expect from visitors alone.
How to Calculate a Sensible Number
Start from what you can observe. Check how many connections your server holds during a busy period, using the Nginx stub status page or by counting established connections on ports 80 and 443. If your busiest hour shows 400 simultaneous connections across 2 workers, each handles about 200, and a limit of 1024 per worker gives you roughly five times headroom.
A practical formula is to take your expected peak connections, divide by the number of worker processes, and double the result. The doubling leaves room for traffic spikes and for the upstream connections Nginx opens to PHP-FPM or a proxied backend. The number you land on is the nginx max connections each worker should allow: with a peak of 500 connections across 2 workers, that works out to 500 per worker, so 1024 is a sensible round number.
One more ceiling matters: the file descriptor limit. Every connection uses a file descriptor, and a worker cannot open more connections than its worker_rlimit_nofile value or the system ulimit -n allows. If you raise worker connections to 4096 but the worker can only open 1024 files, the extra headroom is imaginary. Check the limit with ulimit -n and raise it with worker_rlimit_nofile first.
As a rough guide: 1024 per worker fits a 1 GB, 1-core VPS, 1024 to 2048 fits a 2 GB, 2-core WordPress server, and 2048 to 4096 fits a 4 GB, 4-core machine hosting several sites.
Signs Your Worker Connections Limit Is Too Low
When Nginx runs out of connections, it does not slow down gracefully. It logs an error and turns new visitors away. The telltale line in the error log reads:
1024 worker_connections are not enough
If you see that line, your limit is too low, and raising it is the fix. The other symptom is a spike in 500 errors during traffic peaks that clears up when traffic drops. Reading the error log regularly catches this early, and our guide to monitoring Nginx error logs and getting alerts on 5xx spikes shows how to set up alerts so you hear about it before your visitors do.
Before you raise the limit, rule out bot traffic. Scrapers and brute-force login attempts can eat hundreds of connections that should have gone to real visitors. If your connection count jumps without a matching jump in real traffic, rate limiting is the better fix than a bigger number. Our walkthrough of Nginx rate limiting with limit_req covers how to slow abusive traffic down before it fills your connection table.
Signs Your Worker Connections Limit Is Too High
A limit that is too high fails more quietly. Memory usage climbs because every accepted connection allocates buffers, and under a sudden burst Nginx accepts thousands of connections that PHP-FPM or your database cannot serve in time. Requests queue, response times grow, and the server can end up slower than it was with a lower limit. The nginx connection limit is also a safety valve: when it is set sensibly, Nginx sheds excess load early instead of letting the whole server grind to a halt.
The other cost is file descriptors. A worker with a 10,000-connection limit but a 1,024 file descriptor limit will log errors about too many open files instead of serving traffic. Raise the file descriptor limit with it, and test the change before you reload using the method in how to test a new Nginx config without taking your site down.
How to Change the Setting Safely
The change itself takes a minute, but do it in order so you can roll back if something looks wrong.
- Open your Nginx config, usually
/etc/nginx/nginx.conf, and find theeventsblock. - Set
worker_connectionsto your calculated number. If that number is above 1024, addworker_rlimit_nofilewith a value at least as high, at the top level of the config. - Test the config with
nginx -t. Fix any syntax error before you go further. - Reload Nginx with
systemctl reload nginx. A reload applies the new setting without dropping existing connections. - Watch the error log for the next hour. Look for “worker_connections are not enough” (still too low) and “too many open files” (file descriptor limit too low).
Do not set the value and forget it. Traffic grows, you add sites, and a number that was generous last year becomes tight. Recheck it every few months or after a big change, such as adding a site or enabling a CDN.
Worker Connections and High-Traffic Events
Flash traffic is where the setting earns its keep. A viral post, a sale, or a link from a large site can multiply your simultaneous connections tenfold in minutes. No static number handles every spike, which is why the formula above doubles the observed peak. If your site regularly gets sudden bursts, a CDN in front of Nginx absorbs much of the spike before it reaches your VPS, and that is often a better investment than raising the limit again. Our guide on how Nginx handles 10,000 simultaneous connections and when it can’t explains where Nginx stops coping on its own and what to put in front of it.
Quick Recap
Nginx worker connections caps the simultaneous connections one worker process can handle. Multiply it by your worker processes for the server total, double your observed peak when you pick a number, and keep the file descriptor limit above it. Watch the error log for the “not enough” message, and revisit the setting as traffic grows. A number chosen from your own traffic beats any default.