NGINX runs a fixed number of worker processes as per the specified configuration. As explained in Chapter 1, Working with NGINX, these worker processes are responsible for all request processing. In the following sections, we will work with NGINX worker parameters. These parameters are mostly part of the NGINX global context.
The
worker_processes
directive controls the number of workers:
worker_processes 1;
The default value for this is 1
, which means that NGINX runs only one worker. The value should be changed to an optimal value depending on the number of cores available, disks, network subsystem, server load, and so on.
As a starting point, set the value to the number of cores available. Determine the number of cores available using lscpu
:
$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4
The same can be accomplished by greping out cpuinfo
:
$ cat /proc/cpuinfo | grep 'processor' | wc...