Nginx basic Configuration Analysis
Recently, due to the fact that the project is not proficient in nginx configuration when it is used together with the LNMP environment, write down and take notes.
Nginx. conf --
User xxx; here, it is configured as the user who needs to run nginx. Some default users are nobady. We recommend that you create another user, for example, nginx, to run nginx with this user. It is best not to use root directly, although this may not cause too much permission issues, it may pose a threat to the security of the service;
Worker_processes indicates the number of processes enabled for nginx. Enabling multiple processes can reduce the I/O workload;
Worker_rlimit_nofile: Change the maximum number of files opened by the worker process (maximum number of file descriptors ). If this parameter is not set, the value is the operating system limit (ulimit-n ). After setting, your operating system and Nginx can process more files than "ulimit-a", so set this value to high, in this way, nginx will not have the problem of "too open files ".
Error_log logs/* is obviously an error log file. Here you can set its level info/debug... it will display some information in the log according to different levels.
Pid logs/nginx. pid; process file; process number
Events
{
Use epoll
Worker_connections 1024 the maximum number of connections in a single process
}
Http {
Include mime. types;
Default_typeapplication/octet-stram;
Character encoding charset UTF-8
Server_tokensoff does not accelerate nginx execution, but it can disable the nginx version number on the error page, which is good for security.
Sendfile on; enable the efficient file transmission mode to enable sendfile () to play a role. Sendfile () can copy data (or any two file descriptors) between the disk and the TCP socket ). Pre-sendfile is used to request a data buffer in the user space before data transmission. Then, use read () to copy data from the file to the buffer zone, and write () to write the buffer zone data to the network. Sendfile () immediately reads data from the disk to the OS cache. Because this copy is completed in the kernel, sendfile () is more effective than combining read () and write () and turning on and off the discard buffer.
Tcp_nopush tells nginx to send all header files in a data packet, instead of sending them one by one. This avoids network congestion.
Tcp_nodelay tells nginx not to cache data, but to send data for a period of time-this attribute should be set for the application when data needs to be sent in a timely manner, in this way, the returned value cannot be obtained immediately when a small piece of data is sent. This will benefit the user's interaction and experience.
(For details about the preceding three parameters, seeHttp://www.bkjia.com/ OS /201306/222745.html)
Access_log off; set whether nginx will store access logs. Disabling this option can make disk read IO operations faster.
Keepalive assigns the keep-alive link timeout time to the client
Send_timeout specifies the response timeout of the client, between two client read operations. If the client does not read any data during this period, nginx closes the connection.
Gzip on; gzip tells nginx to send data in the form of gzip compression. This will reduce the amount of data we send
}