Link Search Menu Expand Document
Table of contents

Worker processor

  1. master process
  2. worker process

worker_process 2;

  • Add this string to config file, to tell nginx to run 2 workers
  • Note: each worker takes one CPU core

worker_process auto;

  • This will auto assign worker to each CPU core

Check CPU

$ nproc  

Command outputs how many core you have

$ lscpu 

List out all cpu, how many cores is CPUs

Add event to nginx config file

events {
    worker_connections 1024;
}

»» Why 1024? ««

Use below command to check worker max connections

$ ulimit -n 

Outputs: 1024

worker_processor (1) x worker_connections (1024) = max connections (1024)

pid Directive

$ ls -l /var/run/n* 

Outputs: 
-rw-r--r-- 1 root root DATE TIME /var/run/n`nginx.pid`

To check where is pid running

Change pid directive, add the below to the nginx.config file

pid /var/run/new_nginx.pid 

Buffers & Timeout

client_body_buffer_size 10k; #in kilobytes
client_max_body_size 8m; 
#in megabytes, if larger than 8m, returns 413 error
client_header-buffer_size 1k; 

client_body_timeout 12;
client_header_timeout 12; 
#max time to receive client headers/body, 12 milliseconds, with 's' (12s) >> second

keepalive_timeout 15; 
#max time to keep a connection open

send_timeout 10;
#max time for the client accept/receive a response 

sendfile on; 
#skip buffering for static files 

tcp_nopush on;
#optimise send file packets

Add dynamic module

./configure --help | grep dynamic