Linux operation and maintenance to develop mind - cluster architecture Nginx (b)

1.nginx.conf structure

Configuration items mentioned in the previous chapter nginx.conf can be divided into three parts, which are part of a global, events part, http part. http server portion comprises a block, and a block comprising a server or a plurality of blocks location, a specific configuration file nginx.conf follows:

#全局部份
……
#events部份
events
{
……
}
#http部份
http
{
    ……
    server{
        ……
        location [patten]
        {}
    }
    server{
        ……
        location [patten]
        {}
        location [patten]
        {}
    }
}

2.main global section Parameter Description

Global part to configure the common settings, mainly the following:

user  nginx nginx;  
worker_processes  4;   
worker_cpu_affinity 0001 0010 0100 1000
worker_rlimit_nofile 65535;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  /data/nginx/log/error.log  info;
pid        /data/nginx/log/pid/nginx.pid;
include    filename; 

2.1 user nginx nginx;

User Groups: Use groups or users running nginx, defined according to the actual demand, usually nginx user, if the root user directly to start, you can modify the root, if nobody, means that all users can run.

2.2 worker_processes 4;

Number when starting the application process started, if you need to modify the proposed changes for the same number of core server CPU, if set to "auto", represents the nginx automatically detected.

2.3 worker_cpu_affinity 0001 0010 0100 1000

By default, Nginx multiple processes are likely to run on a particular CPU or a CPU core, resulting in uneven Nginx process using hardware resources, and therefore bind to different Nginx process CPU in order to take full advantage of the hardware multi-purpose multi-core CPU resources.
Explanation: 0,001,001,001,001,000 indicate on four processes, the first process corresponds to the first CPU core, the second process corresponding to the second CPU core, and so on.

2.4 worker_rlimit_nofile 65535;

The maximum number of open file descriptors nginx process, the value of ulimit -n recommend the best configuration of your server consistent.

2.5 error_log /data/nginx/log/error.log info;

Global error log defined type, which can be placed in main line may be provided separately in the other block, depending on its arrangement position is not the same scope. Log output levels are debug, info, notice, warn, error, crit, etc., which, log debug output of the most detailed, crit output at least.

2.6 pid /data/nginx/log/pid/nginx.pid;

Nginx specified process runs file storage address, note the location behind the pid, the folder path must be correct and folder exists.

2.7 include filename;

Introduce other profiles. You may be arranged in other blocks, except that scope.

3.events section Parameter Description

Effect nginx configuration server or a user's network connection. Maximum number of connections per process, choose an event-driven model which process a connection request, whether to allow a plurality of network connections while receiving, a plurality of open network connections serialization, the specific parameters are as follows:

events {
    accept_mutex on;   
    multi_accept on;  
    use epoll;      
    worker_connections  1024;    
}

3.1 accept_mutex on;

Set-Fi serialized to prevent shock group phenomenon, the default is on.
Thundering herd phenomenon: the arrival of a network connection, multiple processes simultaneously sleep wake up, but only one process can get a link, it will affect the system performance. This represents the set provided here Fi sequences, and to prevent shock group phenomenon.

3.2 multi_accept on;

Each worker process configuration is newly arrived simultaneously receiving a plurality of network connections, the default configuration to an off state, i.e. each worker process can only receive a new network connection arrives.

3.3 use epoll;

Configuring event processing network message-driven model, available options are select, poll, kqueue, epoll, rtsig, / dev / poll and eventport. The default is epoll. epoll is a highly efficient mode for Linux systems, epoll is the preferred mode of operation.

3.4 worker_connections 1024;

Maximum number of connections is provided, the default is 512. Each process the maximum number of allowed connections, may be provided consistent ulimit -n configured.

HTTP module left to the next chapter. . .

Published 18 original articles · won praise 26 · views 6955

Guess you like

Origin blog.csdn.net/weixin_45181224/article/details/104718265