The Nginx default profile name is nginx.conf.
Nginx configuration file is mainly composed of 3 parts, namely main,events,http. Where the main configuration segment is a global universal configuration, the events segment is the network I/O model and the connection limit, HTTP is set for HTTP service.
-Main
Worker_processes 2: At the beginning of the main section of the configuration file, the worker is the number of processes that are working, and the master process is receiving and assigning requests to worker processing. Configuration parameters are typically CPU cores, and if you want to start SSL and gzip you need to set it to twice times the number of CPU cores. (Maximum of 8 recommended)
Worker_cpu_affinity: Use with worker_processes, in high concurrency, by setting the CPU stickiness to reduce the performance loss due to multi-CPU core switching.
worker_cpu_affinity Example: #开启2个进程: worker_processes2; Worker_cpu_affinity on Ten; #开启4个进程: worker_processes4; Worker_cpu_affinity0001 0010 0100 +; #开启8个进程: worker_processes8; Worker_cpu_affinity00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
-Events
Use Epoll: Under the Linux operating system, Nginx uses the Epoll event model by default, and Nginx uses an efficient event model similar to Epoll on the OpenBSD or FreeBSD operating system kqueue. Select is used only when the operating system does not support these efficient models.
Worker_connections 1024: The maximum number of connections that can be processed concurrently by each worker process. Nginx, as a reverse proxy server, calculates 最大连接数 = worker_processes * worker_connections/4 that when Nginx acts as an HTTP server, the calculation formula is divided by 2. Cannot exceedworker_rlimit_nofile设定值。
Worker_rlimit_nofile 65535: The default is no setting and can be limited to the maximum operating system limit of 65535.
-HTTP
Include Mime.types; #文件扩展名与文件类型映射表
Default_type Application/octet-stream; #默认文件类型
Sendfile on; #开启高效文件传输模式, the sendfile instruction specifies whether Nginx invokes the Sendfile function to output the file, reducing the user space to the kernel space of the context switch. For normal applications set to ON, if used for downloading applications such as disk IO heavy load applications, can be set to off to balance disk and network I/O processing speed, reduce the load on the system.
AutoIndex on; #开启目录列表访问, the appropriate download server, the default shutdown.
Keepalive_timeout 65; #长连接超时时间, the unit is the second, long connection request a large number of small files, you can reduce the cost of rebuilding the connection, but if there is a large file upload, 65s without uploading completed will result in failure. If you set the time too long and you have more users, staying connected for a long time can be resource intensive.
Send_timeout 60; #用于指定响应客户端的超时时间. This timeout is limited to the time between two connection activities, and if the client does not have any activity at this time, Nginx will close the connection.
Client_max_body_size 10m; #允许客户端请求的最大单文件字节数. If you upload a larger file, set its limit value.
Client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数.
Http_gzip:
gzip on: Turn on gzip compression output to reduce network transmission.
gzip_min_length 1k: Sets the minimum number of bytes of pages allowed to compress, and the number of page bytes is obtained from header content-length. The default value is 20. It is recommended to set the number of bytes greater than 1k, which may be more or less larger than 1k.
gzip_buffers 4 16k: Sets the system to obtain a compressed result data stream for several units of cache used to store gzip. 4 16k represents a 16k unit, with the original data size of 4 times times 16k of memory.
gzip_http_version 1.0: Used to identify the version of the HTTP protocol, the previous browser does not support gzip compression, the user will see garbled, so in order to support the previous version added this option, if you use the Nginx reverse proxy and expect to also enable Gzip compression, because the terminal communication is http/1.0, so please set to 1 .0.
gzip_comp_level 6: gzip compression ratio, 1 compression than the minimum processing speed, 9 compression than the maximum but the processing speed is the slowest (fast transmission but CPU consumption) gzip_types : matching MIME type compression, regardless of whether specified, the "text/html" type will always be compressed.
gzip_proxied any: Nginx is enabled as a reverse proxy, the decision to turn on or off the return of the backend server is compressed, as long as the backend server must return the header containing "Via".
gzip_vary on: With the HTTP header, a vary:accept-encoding is added to the response header, allowing the front-end cache server to cache the gzip-compressed page.
Http_proxy:
Proxy_connect_timeout 60;
Nginx-to-backend server connection time-out (proxy connection timed out)
Proxy_read_timeout 60;
Timeout between two successful response operations with back-end server after successful connection (proxy receive timeout)
Proxy_buffer_size 4k;
Set the proxy server (Nginx) from the backend Realserver read and save the user header information buffer size, the default is the same size as proxy_buffers, you can actually set this instruction value smaller
Proxy_buffers 4 32k;
Proxy_buffers buffer, Nginx for a single connection cache from the backend realserver response, the average web page below 32k, so set
Proxy_busy_buffers_size 64k;
Buffer size under high load (proxy_buffers*2)
Proxy_max_temp_file_size 0;
When Proxy_buffers does not fit the response content of the backend server, a portion is saved to the temporary file of the hard disk, which is used to set the maximum temporary file size, the default 1024M, which is not related to Proxy_cache. Greater than this value, will be returned from the upstream server. Set to 0 disabled.
Proxy_temp_file_write_size 64k;
This option restricts the size of the temporary file to be written each time the cached proxy server responds to a temporary file. Proxy_temp_path (which can be compiled at the time) specifies which directory to write to.
Server: A corresponding server configuration item for each virtual host that contains the configuration of the virtual host associated with the configuration item.
Upstream: A simple scheduling algorithm for client IP to back-end server load balancing.
A series of configuration items that correspond to some specific URLs in the Location:http service.
Nginx (2)---configuration file