Nginx master and worker processes explained
Who does the work?
A process is a running instance of a program. In the normal Nginx process model, the master coordinates configuration and workers; the workers serve traffic. A worker can handle many connections by responding to events rather than dedicating a new process to each request. The master is not a separate HTTP backend.
PID PPID ROLE4100 3900 master4101 4100 worker4102 4100 workerPID identifies a process; PPID identifies its parent. In the illustration the two workers have the same parent. These identifiers are invented: never use them in a signal command. A reload can keep the master while replacing the worker generation.
Configure a small process count
worker_processes 2;pid logs/nginx.pid;events { worker_connections 32;}The worker count and PID path belong at main scope; the connection limit belongs within events. A connection is not the same as a visitor or request: clients can reuse connections and proxying may consume additional connections to upstream servers. File descriptor limits and workload behavior also matter. The example is a small teaching setup, not capacity sizing advice. worker_processes auto; asks Nginx to detect available CPUs; tune it only with evidence.
Identify the master without guessing
These examples use the Chapter 4 disposable lab, not a system Nginx service. The optional commands require a reviewed patched Linux Nginx binary, unprivileged user, a private lab directory and an available loopback port. Expected outputs are predictions, not recorded executions. Once you have started your own lab instance, its configured PID file identifies the master. Read only the lab file and inspect the resulting process. Confirm ownership and identity; stale files and reused process IDs make blind signaling unsafe.
master_pid=$(cat "$LAB/logs/nginx.pid")ps -p "$master_pid" -o pid,ppid,user,argsThe PID value varies per execution. The inspected command should belong to the exact lab instance you started. If the file is absent or the process does not match, stop and investigate rather than creating a PID file by hand. A service manager may supervise a master differently from a manually started lab.
Background and foreground modes
daemon off;master_process on;Foreground operation is useful when an external supervisor owns the process. It does not mean every request runs in the master: the usual worker model remains enabled. master_process off; is a developer-oriented setting, not a normal troubleshooting fix. A packaged service may use its own management commands and user settings. Do not start a second unmanaged instance or mix service-manager commands with the lab commands.
Use an unprivileged isolated lab with a high loopback port. Do not change host permissions or assume a root master is required. Never equate worker count multiplied by worker_connections with real request throughput.
Practice: interpret a process tree
Explain what would change if two replacement workers appear beneath the same master. Identify the file that connects a control command to the intended instance, and why that file is not proof of process identity. Next, learn how to reload and shut down safely.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Master and worker processes
Check the concepts taught in this lesson.
In the ordinary process model, who serves client requests?
Two workers have a PPID of 4100. What does that indicate?
Which context contains worker_connections?
Why is worker_connections not the number of users?
What should you check before signaling a PID read from a lab file?