# The number of worker_processes should be no more than the number of cores of the server's CPU, # Each CPU core of more than 1 worker does not make nginx performance has any promotion worker_processes 4; # The number of file descriptors used for Nginx. This needs to be set up system kernel parameter ' ulimit-n 200000 ' or modify '/etc/security/limits.conf ', reference "High load Linux tuning" Worker_rlimit_ Nofile 200000; # set how many clients per worker process can serve, # max clients = worker_connections * worker_processes # "Max Clients" is also a socket connection that the system can use (Socke T connections) is limited to about 64K worker_connections 1024; # for Linux systems, choose Epoll so that each thread can serve more clients with the use Epoll; # after Nginx gets a notification of a new connection, accept as many connections as possible # Note: If the worker_connections setting is too low, this may cause congestion multi_accept on; # Cache Open File Descriptor (open FDs), frequently accessed file information. # setting these values appropriately can greatly increase the number of requests per second. # The actual set value is not necessarily the same as the following, please tune it according to the specific machine. The following are just a set example in a test environment. Open_file_cache max=200000 inactive=20s; Open_file_cache_valid 30s; Open_file_cache_min_uses 2; Open_file_cache_errors on; # buffer Log writes can accelerate I/O, or even if possible, to see specific production environment requirements. #access_log/var/log/nginx/access.log main buffer=16k; Access_log off; # using Sendfile to copy data from a file descriptor (FD) in the Linux kernel to another file description character read () + write () is more efficient, # Because of the way read () + write () needs to transmit data back and forth in user space Sendfile on; # using Tcp_nopush causes Nginx to attempt to send its HTTP response header (HTTP response head) using a packet, instead of using a partial frame # (partial frames). Append the header before calling Sendfile ( prepending headers) or for throughput optimization, # is very useful. Tcp_nopush on; # do not buffer data forwarding (data-sends) (Prohibit Nagle algorithm). # set to On is ideal for sending small data frequently in real time. (such as pictures, pdf,ppt files, etc., which are not small data, should be set to OFF) Tcp_nodelay on; # keep-alive The timeout for the connection. The server closes this connection after this timeout period. Keepalive_timeout 30; # The number of client requests that can be connected through keep-alive. The following value is only used in the test environment, the specific settings, according to the actual machine to tune. Keepalive_requests 100000; # After the client stops responding, allow the server to shut down the connection, releasing the memory associated with the socket reset_timedout_connection on; # set timeout for client read requests, the default is 60s client_body_timeout 10; # Set the response timeout for the client. If the client stops reading the data, after so much time releases the expired client connection, the default is 60s Send_timeout 2; # compression settings. Reduce the amount of data transmitted by the network. gzip on; Gzip_min_length 10240; Gzip_proxied expired No-cache No-store private auth; Gzip_types text/plain text/css text/xml text/javascript application/x-javascript; Gzip_disable "MSIE [1-6]\."; Here is a complete tuning example:
User www www. Worker_processes 4; Worker_cpu_affinity 000000000000000000000001 000000000000000000000010 000000000000000000000100 000000000000000000001000 000000000000000000010000 000000000000000000100000 000000000000000001000000 000000000000000010000000 000000000000000100000000 000000000000001000000000 000000000000010000000000 000000000000100000000000 000000000001000000000000 000000000010000000000000 000000000100000000000000 000000001000000000000000 000000010000000000000000 000000100000000000000000 000001000000000000000000 000010000000000000000000 000100000000000000000000 001000000000000000000000 010000000000000000000000 100000000000000000000000; Worker_rlimit_nofile 100000; PID Logs/nginx.pid; Error_log Logs/error.log Crit; Events {# Maximum clients = worker_processes * worker_connections worker_connections 1024; multi_accept on; #google_perftools_profiles Log/profile; HTTP {# Basic Settings sendfile on; Open_file_cache max=100000 inactive=20s; open_file_cache_valid 30S Open_file_cache_min_uses 2; Open_file_cache_errors on; Tcp_nopush on; Tcp_nodelay on; Keepalive_timeout 20; #keepalive_requests 100000; Reset_timedout_connection on; Client_max_body_size 15m; Client_body_timeout 60; Client_header_timeout 60; Client_body_buffer_size 128K; Client_header_buffer_size 1k; Large_client_header_buffers 4 32k; Send_timeout 60; Types_hash_max_size 2048; Server_tokens off; Include Mime.types; Default_type text/html; CharSet Utf-8; # Log Format log_format main ' $remote _addr-$remote _user [$time _local] ' $request ' $status $body _bytes_sent ' $http _refe "RER" "$http _user_agent" "$http _x_forwarded_for"; # gzip Settings gzip on; Gzip_static on; Gzip_disable "MSIE [1-6]\."; Gzip_vary on; Gzip_proxied any; # gzip_proxied expired No-cache no-store private auth; Gzip_comp_level 2; Gzip_min_length 5000; Gzip_http_version 1.1; Gzip_buffers 8k; Gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/ X-javascript APPlication/json application/xml application/rss+xml font/truetype Application/x-font-ttf font/opentype Vnd.ms-fontobject Image/svg+xml; Ignore_invalid_headers on; #Virtual Host configs include conf.d/*; Include sites-enabled/*.conf; }