How Nginx Handles Requests: Master & Worker Process Deep Dive
This article explains Nginx's high‑performance architecture, detailing the roles of the Master and Worker processes, their responsibilities, and the step‑by‑step workflow from receiving a client request to generating and sending the HTTP response.
Nginx is a high‑performance HTTP server and reverse proxy that also supports IMAP/POP3. It is renowned for handling massive concurrency with low memory usage, thanks to its modular, asynchronous, non‑blocking I/O design, making it a core component of modern web architectures.
Architecture Overview
Nginx runs a multi‑process model consisting of a single Master process and multiple Worker processes. The Master process loads configuration, starts, stops, and restarts Workers, and handles OS signals, while the Workers handle client connections, read/write operations, and module execution.
Master Process Responsibilities
Load and parse the nginx.conf configuration file.
Manage Worker processes: start, stop, and restart them.
Handle signals from the operating system (e.g., reload configuration, graceful upgrade).
Does not process client requests directly.
Worker Process Responsibilities
Each Worker runs independently and processes actual client requests.
Handles connection I/O, reads HTTP headers, parses URIs, and executes configured modules.
Worker count is typically set based on CPU core count to maximize hardware utilization.
Workers are isolated from each other, enhancing stability and concurrency.
Request Handling Workflow
The overall request flow proceeds as follows:
Receive Request: A client sends an HTTP request, which a Worker process accepts.
Parse Request: The Worker parses the request line, headers, and URI.
Process Request: Based on the configuration, the request is handed to the appropriate module. Typical actions include:
Serving static files directly.
Reverse proxying to upstream servers.
Load balancing across multiple backends.
Returning cached responses.
Generate Response: After processing, Nginx creates an HTTP response.
Send Response: The Worker sends the response back to the client.
Understanding these components helps in tuning Nginx for optimal performance, scaling, and reliability in production environments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
