How to Tune Nginx Worker Processes for a Busy WordPress Site

When a WordPress site gets busy, the first thing most owners blame is PHP or the database. Often the bottleneck sits one layer earlier: Nginx itself. To tune nginx worker processes is to decide how many CPU cores Nginx uses to serve requests and how many connections each of those processes can hold open at once. Get those two numbers wrong and the server either idles on unused cores or queues visitors it could have served.

What nginx worker processes actually do

Nginx runs a master process that reads the configuration and a set of worker processes that do the real work: accepting connections, reading requests, serving static files, and passing PHP requests to PHP-FPM. Each worker runs on one CPU core at a time, and the worker processes WordPress requests through an event loop instead of spawning a thread per visitor. That design is why Nginx stays light under load, but it also means the worker count and the per-worker connection limit decide how much traffic the server can absorb at once.

If the vocabulary is new, start with our explainer on what nginx worker connections are and how many you actually need before touching the config.

Check your starting point before changing anything

Never tune blind. Three commands tell you what you are working with. Run nproc to see how many CPU cores the VPS has, and free -m to see how much RAM is free after MySQL and PHP-FPM take their share. Then open /etc/nginx/nginx.conf and note the existing worker_processes and worker_connections values, or the lack of them.

Check the error log too: tail -n 100 /var/log/nginx/error.log. Two messages point straight at worker misconfiguration. “worker_connections are not enough” means visitors are being turned away because every connection slot is full. “accept4() failed (24: Too many open files)” means the operating system ran out of file descriptors before Nginx ran out of connections. They need different fixes, so knowing which one you have matters.

How to tune nginx worker processes to match your CPU

The rule most admins settle on is simple: one worker per CPU core. Nginx makes this easy with a single value:

worker_processes auto;

With auto, Nginx detects the core count at startup and spawns one worker per core. On a 2-core VPS you get two workers, on an 8-core server you get eight, and the setting stays correct if you resize the VPS later. This is the right default for almost every busy WordPress site, and it is what you should use unless you have a specific reason not to.

The exception is a server where Nginx shares the box with heavy neighbors. If the same VPS also runs MySQL, Redis, and a mail server, pinning workers to a fixed number leaves cores for the other services. Setting worker_processes 2; on a 4-core box that also hosts a database is a reasonable compromise. Only pin the count when another service genuinely needs the cores, and remember that adding workers past the core count never adds speed.

Set worker_connections for real traffic

Nginx worker connections decide how many simultaneous connections each worker can hold. The default of 1024 per worker suits a quiet site and is tight for a busy one. The maximum clients Nginx can serve at once is roughly:

max clients = worker_processes x worker_connections

With two workers at 1024 connections each, the ceiling is about 2048 simultaneous connections, and it shrinks further because a proxied PHP request can use two connections at once. A site that spikes to a few hundred concurrent visitors during a sale or a viral post can hit that ceiling faster than owners expect.

A practical starting point for a busy WordPress site on a 2 to 4-core VPS is 2048 or 4096 connections per worker, set inside the events block:

events {
    worker_connections 2048;
    multi_accept on;
    use epoll;
}

Raise the number only as far as your file descriptor limit allows. Each connection needs a file descriptor, so worker_connections multiplied by worker_processes must stay below the limit set by worker_rlimit_nofile and the system-wide limit. Doubling worker_connections without raising the file limit just moves the failure from “not enough connections” to “too many open files”.

Tune the settings around the workers

Keepalive connections. Browsers reuse connections when keepalive_timeout is set sensibly, typically 65 seconds, and keepalive_requests allows a few hundred requests per connection. Without keepalive, every asset on the page costs a fresh connection. With keepalive set too long, idle connections sit in the pool and block slots for real visitors. For WordPress, keepalive_timeout 65; with keepalive_requests 100; is a solid middle ground.

Open file cache. WordPress serves many small static files: theme assets, uploads, plugin scripts. open_file_cache lets Nginx remember file handles instead of opening the same files from disk on every request, which takes pressure off workers during traffic spikes. Enable it with a short inactive window, for example open_file_cache max=10000 inactive=30s;.

Sendfile and TCP tuning. sendfile on; and tcp_nopush on; let the kernel move static files to the network with less copying, freeing workers to handle the next request sooner. These are small wins individually, but on a busy site they add up, and they cost nothing to enable.

Worker tuning also pairs well with caching. If most visitors see the same pages, a FastCGI cache setup in Nginx takes the majority of requests off PHP entirely, so the workers you tuned have far less work to do.

Match PHP-FPM to your worker settings

Nginx workers hand every dynamic request to PHP-FPM, and a mismatch between the two pools is one of the most common causes of slow WordPress admin pages and checkout timeouts. If Nginx can accept 4096 connections but PHP-FPM only runs 10 children, most of those connections wait in a queue while PHP works through them one at a time. The pools need to grow together.

As a rule of thumb, start with pm.max_children sized to your RAM: divide the memory left after MySQL and the system by the average memory of one PHP process, usually 30 to 50 MB. On a 2 GB VPS, 20 to 30 children is a realistic range; on 4 GB, 40 to 60. If PHP response times climb while CPU still has headroom, the PHP pool is the bottleneck, not the workers. Our guide to fixing slow Nginx response times caused by PHP-FPM walks through diagnosing that split, and the PHP-FPM pm settings for a 2 GB VPS shows the math for a small server.

Test, reload, and watch the numbers

Never reload Nginx without testing the config first. A typo in nginx.conf stops the whole server from starting, and on a busy site that means downtime in front of real visitors.

sudo nginx -t
sudo systemctl reload nginx

nginx -t checks the syntax and reports the file and line of any error. reload then applies the new settings without dropping existing connections, unlike a full restart. If the test passes and the reload succeeds, watch the results for at least a day of real traffic: error log entries, response times, and CPU load during the busiest hour. Judge the change by peak traffic, not by an idle moment. For a safe workflow around config edits, see our steps to test a new Nginx config without taking your site down.

Two numbers tell you whether the tuning worked. First, the error log should stop showing connection and file-descriptor warnings during peak hours. Second, time to first byte on uncached pages should drop or at least stop spiking when traffic rises. If neither changes, the bottleneck was never the workers: look at the database or a heavy plugin next.

Common mistakes that make things slower

Worker tuning is easy to get wrong in ways that look like progress. Setting worker_processes to 16 on a 2-core VPS adds context-switching overhead without adding capacity. Raising worker_connections to 10000 without raising the file descriptor limit trades one error message for another. Turning keepalive off to “free” connections just forces browsers to reconnect for every image and script, which burns more worker time than it saves.

Good nginx worker tuning starts with the hardware, not with a config copied from a forum: one worker per core, worker_connections sized to real traffic, file limits above the total, and PHP-FPM grown alongside Nginx. Then measure at peak traffic. The other classic mistake is tuning Nginx while ignoring everything behind it: a perfectly tuned worker pool in front of a MySQL server with a starved buffer pool, or a WordPress install running twenty heavy plugins, still serves slow pages. Nginx tuning removes the web server from the list of suspects. Tune one layer at a time, measure after each change, and keep notes so you can roll back the one edit that made things worse.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.