NGINX Architecture: Master Process, Worker Processes and the Event Loop

How NGINX handles thousands of connections: master and worker processes, epoll event loop, non-blocking I/O, worker_connections and zero-downtime reloads.

Published November 27, 2026

NGINX serves huge amounts of traffic with very little memory, and it can reload its configuration or even upgrade its own binary without dropping a single connection. Both abilities come from its process architecture. Understanding it helps you tune worker settings correctly and explains what really happens when you run systemctl reload nginx.

The concept

NGINX starts a single master process, usually as root so it can bind to ports 80 and 443 and read certificates. The master reads the configuration, opens listening sockets, and forks worker processes that run as an unprivileged user such as www-data. The master never handles requests itself; it manages workers, reloads configuration, and reopens log files.

Each worker is single-threaded and runs an event loop. Instead of blocking while waiting for a client to send data or a backend to respond, the worker asks the kernel (via epoll on Linux) to notify it when any of its sockets becomes ready, then handles whichever events are ready. One worker can juggle thousands of connections because it never sits idle waiting on any single one.

Typically you run one worker per CPU core (worker_processes auto). The theoretical maximum number of client connections is worker_processes × worker_connections, though proxied requests use two connections each (client and backend), and the operating system's open file limit must be high enough.

The process model

Kernellistening socket :443Master (root)config, signalsWorker 1event loop, ~thousands connsWorker 2event loopWorker 3event loopCache managerprunes disk cache
One master, several workers, plus cache helper processes.

Inside a worker

  1. epoll_wait(): sleep until any socket is ready
  2. Accept new connections, read request bytes that have arrived
  3. Parse and route the request; start a backend or file read
  4. Write whatever response data the socket can take now
  5. Loop: never block on any single connection
One iteration of a worker's event loop.

How a zero-downtime reload works

adminmasterold workersnew workersSIGHUP (reload)parse + validate new configfork with new configgraceful shutdownfinish in-flight requests, exit
A reload replaces workers without dropping connections.

Controlling the master with signals

Signal / commandEffect
nginx -s reload / SIGHUPRe-read config, start new workers, gracefully stop old ones
nginx -s reopen / SIGUSR1Reopen log files (used by logrotate)
nginx -s quit / SIGQUITGraceful shutdown: finish requests then exit
nginx -s stop / SIGTERMFast shutdown
SIGUSR2 then SIGWINCH/SIGQUITLive binary upgrade without downtime

Practical examples

Tune workers and file limits

Match workers to cores and raise per-worker file descriptor limits.

worker_processes auto;
worker_rlimit_nofile 65535;
events {
    worker_connections 8192;
    multi_accept on;
}

See the processes and their state

Each worker shows its own PID; reloads give workers new PIDs.

ps -o pid,ppid,user,cmd -C nginx
sudo nginx -s reload && sleep 1 && ps -o pid,cmd -C nginx

Offload blocking file reads to thread pools

Large files on slow disks can block a worker; thread pools prevent that.

thread_pool default threads=32 max_queue=65536;
location /downloads/ {
    aio threads;
    directio 4m;
}

Common mistakes

  • Setting worker_processes much higher than the number of CPU cores, adding context switching for no benefit.
  • Raising worker_connections without raising the open file limit (worker_rlimit_nofile, LimitNOFILE in systemd).
  • Restarting instead of reloading, which drops connections the reload would have preserved.
  • Running slow blocking work in Lua or third-party modules inside the event loop, stalling every connection on that worker.

Key takeaways

  • A root master manages unprivileged single-threaded workers.
  • Workers use epoll and non-blocking I/O to handle thousands of connections each.
  • worker_processes auto plus adequate worker_connections and file limits is the baseline.
  • Reloads start new workers and drain old ones, so they cause no downtime.

FAQ

Why are there more NGINX processes than CPU cores?

Besides workers, NGINX runs a cache manager and cache loader when proxy caching is configured, and old workers may still be draining after a reload.

Is NGINX multi-threaded?

Workers are single-threaded for request processing. Optional thread pools exist only for offloading blocking operations such as file reads.

What is the accept mutex?

An older mechanism to stop all workers waking up for every new connection. With EPOLLEXCLUSIVE or reuseport on modern Linux, it is off by default.

More Nginx articles