Main Configuration File

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

A downloadable version is available here

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#
# Nginx Main Configuration file
#

# Run as a less privileged user for security reasons.
user                    www-data;

# The maximum number of connections for Nginx is calculated by:
# max_clients = worker_processes * worker_connections

# How many worker threads to run.
# Ideally set to the number of CPU cores or "auto" to autodetect.
# Default: 1
worker_processes        auto;

# Binds worker processes to the sets of CPUs.
# Default: not set
worker_cpu_affinity     auto;

# Max. number of connections per worker
# Default: 512
events {
    worker_connections  2048;
}


# Maximum open file descriptors per process;
# should be higher worker_connections.
# Default: not set
worker_rlimit_nofile    4098;

pid                     /var/run/nginx.pid;

http {

    # Default HTTP configuration options
    include /etc/nginx/http-conf.d/*.conf;

    # Logging - Please remove, after debugging.
    #include /etc/nginx/log-debug.conf;

    # Virtual server configurations
    include /etc/nginx/servers-enabled/*.conf;
}

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).