Nginx worker_processes Explained: Configuration, Performance, and Best Practices
Introduction
The worker_processes directive determines how many worker processes Nginx creates to handle incoming client connections. Since each worker process can process many simultaneous connections using Nginx's event-driven architecture, selecting an appropriate value is an important step in optimizing server performance.
Modern versions of Nginx support automatic worker process detection, making configuration easier for most systems. However, understanding how this directive works helps administrators build efficient and scalable web servers.
This guide explains how worker_processes works, how to configure it, recommended values, and common configuration mistakes.
Test Environment
What Is worker_processes?
Nginx uses a master process and one or more worker processes.
The master process manages configuration and worker lifecycles, while worker processes handle client requests.
The worker_processes directive specifies how many worker processes Nginx should create.
Example:
worker_processes auto;
or
worker_processes 4;
How It Works
Nginx starts a single master process.
Each worker can manage many concurrent client connections without creating additional threads for every request.
Why Multiple Workers?
Modern CPUs contain multiple cores.
Example:
Using multiple worker processes allows Nginx to utilize multiple CPU cores simultaneously.
If only one worker is configured:
worker_processes 1;
only one CPU core performs most request processing.
Check the Current Configuration
The directive is usually located in:
/etc/nginx/nginx.conf
View the configuration:
grep worker_processes /etc/nginx/nginx.conf
Example:
worker_processes auto;
Change worker_processes
Open the configuration file.
sudo nano /etc/nginx/nginx.conf
Example:
worker_processes auto;
or
worker_processes 8;
Save the file.
Test the Configuration
Always verify the configuration before reloading Nginx.
sudo nginx -t
Example output:
nginx: the configuration file syntax is ok
nginx: configuration file test is successful
Reload Nginx
Apply the changes.
sudo systemctl reload nginx
Verify:
sudo systemctl status nginx
Expected output:
Active: active (running)
What Does auto Mean?
Modern Nginx versions support automatic CPU detection.
worker_processes auto;
If your server has:
2 CPU Cores
Nginx creates:
2 Worker Processes
If the server has:
8 CPU Cores
Nginx creates:
8 Worker Processes
This is generally the recommended configuration because it automatically adapts to different hardware.
Recommended Values
For almost all production servers:
worker_processes auto;
is the recommended choice.
worker_processes vs worker_connections
These directives control different aspects of Nginx.
Example:
If:
Worker Processes : 4
Worker Connections : 4096
The theoretical maximum number of concurrent connections is approximately:
4 × 4096 = 16384 connections
Actual capacity depends on factors such as keepalive connections, file descriptor limits, upstream services, and available memory.
Common Issues
Too Few Worker Processes
Example:
worker_processes 1;
On a server with eight CPU cores, only one worker actively handles requests.
Result:
Lower CPU utilization.
Reduced throughput.
Increased response time under heavy load.
Too Many Worker Processes
Example:
worker_processes 64;
on a four-core server.
Possible consequences:
Excessive context switching.
Increased CPU overhead.
No meaningful performance improvement.
More workers do not automatically make Nginx faster.
High CPU Usage
High CPU usage is not always caused by worker_processes.
Other possible causes include:
PHP-FPM bottlenecks.
Slow upstream applications.
Compression of large responses.
Inefficient application code.
Heavy logging.
Investigate the entire request path before changing worker settings.
Relationship with Other Directives
worker_processes works together with several global directives.
Tuning these settings together generally produces better results than modifying only one directive.
Best Practices
Use worker_processes auto on modern Linux servers.
Test the configuration with nginx -t before reloading.
Tune worker_connections together with worker_processes.
Monitor CPU usage under real workloads before making changes.
Avoid setting a value higher than the available CPU cores unless you have a specific reason and have benchmarked the configuration.
Conclusion
The worker_processes directive determines how many worker processes Nginx creates to handle client requests. Since each worker can efficiently manage many simultaneous connections, selecting the appropriate number of workers helps maximize CPU utilization and overall server performance.
For nearly all production environments, worker_processes auto is the recommended configuration because it automatically matches the number of available CPU cores. Combined with proper tuning of worker_connections, sendfile, and keepalive_timeout, it provides a strong foundation for building high-performance Nginx servers.
Explore More
› Nginx Explained: Essential Configuration Directives and Best Practices
› Nginx worker_connections Explained: Configuration, Limits, and Best Practices
› Nginx keepalive_timeout Explained: Configuration, Performance, and Best Practices
› Nginx client_max_body_size Explained: Configuration, Upload Limits, and Best Practices
› Best Areas to Live in Bangkok in 2026: A Complete Guide for Expats and Digital Nomads
› Best Coworking Spaces in Bangkok 2026: A Guide for Digital Nomads and Remote Workers
› Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
› Best eSIM for Southeast Asia in 2026: Compare the Top Travel eSIMs