Nginx worker_connections Explained: Configuration, Limits, and Best Practices
Introduction
The worker_connections directive specifies the maximum number of simultaneous connections that each Nginx worker process can handle. Together with worker_processes, it determines the theoretical maximum number of client connections that an Nginx server can manage.
Choosing an appropriate value is essential for busy websites and APIs. A value that is too low may limit concurrency, while an excessively high value may exceed operating system limits or consume unnecessary resources.
This guide explains how worker_connections works, how it interacts with other Nginx directives, recommended values, and common configuration mistakes.
Test Environment
What Is worker_connections?
The worker_connections directive specifies the maximum number of simultaneous connections that a single Nginx worker process can handle.
Example:
In this example, each worker process can manage up to 4,096 connections.
Where Is worker_connections Configured?
Unlike many other directives, worker_connections must be placed inside the events block.
Example:
events {
worker_connections 4096;
}
It cannot be placed inside the http, server, or location blocks.
How It Works
Suppose the configuration is:
Nginx creates four worker processes.
The theoretical maximum number of concurrent connections is:
4 × 4096 = 16384 connections
This is a theoretical limit. Actual capacity depends on several other factors.
Relationship with worker_processes
The two directives work together.
Formula:
Maximum Connections ≈
worker_processes × worker_connections
Example:
Remember that these are theoretical values and do not necessarily represent the number of simultaneous website visitors.
Check the Current Configuration
Open the configuration file:
/etc/nginx/nginx.conf
Search for the directive:
grep worker_connections /etc/nginx/nginx.conf
Example:
worker_connections 4096;
Change worker_connections
Edit the configuration.
sudo nano /etc/nginx/nginx.conf
Example:
Save the file.
Test the Configuration
Always verify the configuration.
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)
Recommended Values
For most production servers:
is a reasonable starting point.
Operating System Limits
Increasing worker_connections alone does not guarantee that Nginx can actually accept more connections.
Linux also limits the number of open file descriptors.
Check the current limit:
ulimit -n
Example:
1024
If worker_connections exceeds the available file descriptor limit, Nginx may not be able to use the configured value effectively.
Common Issues
Too Few Connections
Example:
worker_connections 128;
Possible symptoms:
New clients are rejected during peak traffic.
Increased request latency.
Connection errors.
Excessively Large Values
Example:
worker_connections 65535;
Possible issues:
Exceeds operating system limits.
Consumes additional memory.
Provides little benefit on low-traffic servers.
Choose values that match your workload instead of simply selecting the largest possible number.
Confusing Connections with Visitors
A common misconception is that:
4096 Connections = 4096 Users
This is not necessarily true.
One visitor may open multiple connections for:
HTML
CSS
JavaScript
Images
API requests
Keepalive connections
Therefore, the number of concurrent users is usually lower than the maximum connection count.
Relationship with Other Directives
worker_connections is closely related to several global Nginx directives.
Optimizing these directives together generally provides better performance than adjusting only one setting.
Best Practices
Use worker_processes auto together with an appropriate worker_connections value.
Ensure the operating system file descriptor limit is high enough.
Test the configuration with nginx -t before reloading.
Monitor connection usage under production workloads.
Increase connection limits gradually rather than choosing excessively large values without measurement.
Conclusion
The worker_connections directive determines how many simultaneous connections each Nginx worker process can handle. Together with worker_processes, it defines the server's theoretical connection capacity and plays a key role in handling concurrent traffic efficiently.
For most production environments, a value of 4096 provides a good balance between scalability and resource usage. However, the optimal configuration also depends on available system resources, operating system limits, and the characteristics of your applications.
Explore More
› Nginx client_max_body_size Explained: Configuration, Upload Limits, and Best Practices
› MariaDB max_connections Explained: Configuration, Limits, and Best Practices
› Nginx Explained: Essential Configuration Directives and Best Practices
› Nginx worker_processes Explained: Configuration, Performance, 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