Main Configuration File

The main configuration file is /etc/nginx/nginx.conf.

A downloadable version is available here

 1#
 2# Nginx Main Configuration file
 3#
 4
 5# Run as a less privileged user for security reasons.
 6user                    www-data;
 7
 8# The maximum number of connections for Nginx is calculated by:
 9# max_clients = worker_processes * worker_connections
10
11# How many worker threads to run.
12# Ideally set to the number of CPU cores or "auto" to autodetect.
13# Default: 1
14worker_processes        auto;
15
16# Binds worker processes to the sets of CPUs.
17# Default: not set
18worker_cpu_affinity     auto;
19
20# Max. number of connections per worker
21# Default: 512
22events {
23    worker_connections  2048;
24}
25
26
27# Maximum open file descriptors per process;
28# should be higher worker_connections.
29# Default: not set
30worker_rlimit_nofile    4098;
31
32pid                     /var/run/nginx.pid;
33
34http {
35
36    # Default HTTP configuration options
37    include /etc/nginx/http-conf.d/*.conf;
38
39    # Logging - Please remove, after debugging.
40    #include /etc/nginx/log-debug.conf;
41
42    # Virtual server configurations
43    include /etc/nginx/servers-enabled/*.conf;
44}

If you don’t set worker_processes to auto on line 13 above. You should set it to the number of CPU cores of your server. To find out how many CPU cores are available, run the following command:

$ cat /proc/cpuinfo | grep processor | wc -l
2

The above configuration example will allow a maximum of 4,096 client connections at the any given time (2 CPU cores which will handle 2,048 connections each).