The configuration file is divided into two parts :
Main Configuration Segment
HTTP Basic Configuration Segment
syntax format, configuration directives to end with a semicolon :
Directive value1 [value2 ...];
support for using variables :
Module built-in variables
Custom variables
Set Var_name value
categories of directives for the main configuration segment :
For debugging, locating problems
Required configuration for normal operation
Configuration for optimized performance
Event-related configuration
instructions for debugging, locating the problem:
1,daemon [Off|on]
whether to start Nginx in daemon mode, default to On
2,master_process on |off
whether to run Nginx with the Master/worker model
3,error_log/path/to/error_log level
error log file and its level; the debug level can be used for debugging purposes, but this level is only valid if the--WITH-DEBUG option is used when compiling nginx
required configuration for normal operation :
1,user Username[groupname];
Specify the users and groups that are running the worker process, for example:
user Nginx nginx;
2. Specify the Nginx PID file
Pid/path/to/pid_file
3.worker_rlimit_nofile #;
Specifies the maximum number of file handles that a worker process can open;
4.worker_rlimit_sigpending #
Specify the number of signals each user can send to a worker
To optimize the performance of the relevant configuration :
1,worker_processes 3;
number of worker threads, typically minus 1 of the number of physical CPU cores
Cat/proc/cpuinfo viewing the core of the CPU
2.worker_cpu_affinity cpumask ...;
binds the worker process to the specified CPU
cpumask
0001 First CPU
0010
0100
1000
Example: worker_cpu_affinity 00000001 00000010 00000100
3,time_resolution t;
resolution of Time
gettimeofday ();
4,worker_priority Nice; Adjust the Nice value ( -20,19), the greater the Nice, the higher the CPU priority
Event-related configuration :
1,accept_mutex[on|off]
a Load balancer lock used internally to invoke a user's request to each worker, and open to allow multiple workers to rotate, serialize, and respond to a new request
2,lock_file/path/to/lock_file;
3,accept_mutex_delay #ms;
4,use[epoll |rgsig|select|poll]
Define the event model used; It is recommended to have Nginx automatically select
5,worker_connection #;
Maximum number of concurrent requests that each worker process can respond to
Network connection-related configurations:
1.keepalive_timeout time;
Keep connected supermarket length, default is 75s
2.keepalive_requests #;
Allow the maximum number of resource requests to be hosted on a single hold connection
3.keepalive_disable [Msie6|safari|none]
Disables long connections for the specified type of browser;
4.tcp_nodelay On|off
Whether the Tcp_nodelay option is used for long connections;
5.client_header_timeout time;
The timeout length of the header of the read HTTP request message
6.client_body_timeout time
Timeout length of the body part of the HTTP request read
7.send_timeout time;
Supermarket duration for sending response messages
To limit the client's requests:
1.limit_except method{...}
Specifies access control for methods other than the scope;
Limit_except get{
Allow 172.16.0.0/16;
Deny All
}
2.client_body_max_size size;
Limit the body portion of the request message and determine the "Content_length" in the header of the request packet.
3.limit_rate speed;
Limit the number of bytes that the client transmits per second, by default 0, which means no limit
allocating memory or disk resources
1.client_body_in_file_only On|clean|off;
The body part of the request message can be staged to the disk, on means allow, the request ends will not delete the staging content, clean run out will clear the disk, off does not allow staging;
2.client_body_in_single_buffer On|off
Whether the body part of the request message can be staged into the buffer of memory and put in it will improve performance
3,client_body_buffer_size size;
4.client_body_temp_path DIR [Level1[level2[level3[level4]]
Example: Client_body_temp_path/var/tmp/nginx/client 1 2
5.client_header_buffer_size size;
MIME Type-related configuration :
1,types{}
Defines the extension of the MIME types to file;
type{
text/html. html;
image/jpeg. jpg;
}
2.default_type Mime-type;
file Operations optimization-related configuration :
1.sendfile On|off;
2.aio On|off;
3.directio Size|off;
Whether to use the O_direct option to request a read file; mutex with Sendfile
4.open_file_cache Max=n[inactive=time] | Off
Nginx can cache the following three kinds of information:
(1) file handle, file size and last modified time;
(2) directory Structure of Open Directory
(3) Information about files that are not found or that do not have permission to operate
Max=n represents the maximum number of entries that can be cached, and once the upper limit is reached, the least recently used entries are removed from the cache using LRU, Inactive=time; cache entries that have not been accessed in inactive for a specified length of time are eliminated and are closed by default
5.open_file_cache_errors On|off;
If there is a cache in the file buffer to open the file when there is no path found, no permissions, etc. error message;
6.open_file_cache_min_uses time;
How often to check the validity of cache entries in the cache; default 60s
This article is from the "Lifelong Learning" blog, please be sure to keep this source http://chickengg.blog.51cto.com/10402610/1696218
Introduction to Nginx Configuration