Beginner Fundamentals

Nginx Architecture

Understanding how Nginx is built helps you tune and troubleshoot it. The design centers on a master process and several worker processes.

Master and Workers

When Nginx starts, it launches one master process. The master:

  • Reads and validates the configuration
  • Binds to ports (such as 80 and 443)
  • Starts and manages worker processes

The workers do the real work: accepting connections and handling requests. Because the master holds privileged tasks, workers can run as an unprivileged user for safety.

The Event Loop

Each worker runs an event loop. Instead of blocking while waiting for I/O, a worker registers interest in events (data ready to read, socket ready to write) and processes them as they arrive.

One worker can juggle thousands of connections at once. This non-blocking model is the core reason Nginx uses little memory under heavy load.

Why It Scales

worker_processes auto;

events {
    worker_connections 1024;
}

worker_processes auto matches the number of CPU cores. worker_connections sets how many connections each worker handles. With 4 cores and 1024 connections each, that is roughly 4096 simultaneous connections.

Graceful Reloads

On reload, the master starts new workers with the new config and lets old workers finish their current requests. No connections are dropped.