Nginx Basic Configuration Analysis

Source: Internet
Author: User
Tags sendfile

Recently, because the project needs to match the LNMP environment with some of the nginx configuration is not proficient, write down to do notes.


Nginx.conf--


User xxx; This is configured as Nginx to run the user, some default is Nobady, it is recommended to create another user for example: Nginx, with this user to run Nginx, it is best not to use root directly, although the words may not have too much permission after the problem, But doing so may pose a threat to the security of the service;


Worker_processes for Nginx Open process number, according to the official hair theory, open multiple can reduce IO burden;

Worker_rlimit_nofile Change the maximum number of open files (maximum file descriptors) for the worker process. If not set, this value is the operating system limit (Ulimit-n). After setting your operating system and Nginx can handle more than "ulimit-a" files, so set this value high, so nginx will not have "too many open files" problem


Error_log logs/* is obviously the error log file here can set its own level info/debug .... It will vary depending on the level of some information in the log rendering also different


PID logs/nginx.pid; process file; Process number


Events

{

Use Epoll; here indicate how it works, I use epoll this high-performance mode of work linux2.6+ best use Epoll *bsd kqueque

worker_connections The maximum number of connections under a single process

}


http{

Include mime.types;

Default_typeApplication/octet-stram;

CharSet UTF-8 character encoding

Server_tokensoff does not allow Nginx to execute faster, but it can turn off the Nginx version number on the error page, which is good for security

Sendfile on; Enable Sendfile () to work by enabling efficient file transfer mode . Sendfile () can copy data (or any two file descriptors) between a disk and a TCP socket. Pre-sendfile is the data buffer that is requested in the user space before the data is transmitted. The data is then copied from the file to this buffer with read (), and write () writes the buffer data to the network. Sendfile () is to immediately read data from disk to the OS cache. Because This copy is done in the kernel, sendfile () is more efficient than combining read () and write () and turning off discard buffers

Tcp_nopush tell Nginx to send all header files in one packet without sending them one after the other . Doing so can avoid network congestion

Tcp_nodelay tells Nginx not to cache the data, but a paragraph of the send-when the need to send data in a timely manner, it should be set to the application of this property, so that a small piece of data can not be sent immediately return value , Doing so can be beneficial in user interaction and experience

(The details of the above three parameters can be seen http://www.2cto.com/os/201306/222745.html)

Access_log off; sets whether Nginx will store access logs. Turn off this option to make read disk IO operations faster

KeepAlive assigning keep-alive link time-outs to clients

SEND_TIMEOUT Specifies the response time-out for the client, between two client read operations. If during this time, the client does not read any data, Nginx will close the connection

gzip on; Gzip is to tell Nginx to send data in the form of gzip compression. This will reduce the amount of data we send

}


Nginx Basic Configuration Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.