1: first install the library required by nginx
A. GCC compiler
Yum install-y gcc
B. G ++ Compiler: C ++ to compile the HTTP module of nginx
Yum install-y gcc-C ++
C. PCRE Library: Regular Expression
Yum install-y PCRE-devel
D. zlib library
Gzip compression of HTTP packet content
Yum install-y zlib-devel
E. OpenSSL Development Library
If the server needs to support HTTP transmission over the SSL protocol, OpenSSL is required.
Yum install-y OpenSSL-devel
2: Prepare the disk directory
A. nginx source code storage directory
B. Directory for storing intermediate files generated during nginx Compilation
C. nginx deployment directory
D. nginx log storage directory
3: Parameter Adjustment
To configure high-concurrency Web servers, you also need to optimize Linux kernel parameters.
When nginx is configured as a static Web Content Server, reverse proxy server, or a server that provides image thumbnails (real-time image compression), its kernel parameters are adjusted differently.
First, modify/etc/sysctl. conf to change the kernel parameters.
fs.file-max=999999 net.ipv4.tcp_tw_reuse= 1 net.ipv4.tcp_keepalive_time= 600 net.ipv4.tcp_fin_timeout= 30 net.ipv4.tcp_max_tw_buckets=5000net.ipv4.ip_local_port_range= 1024 61000 net.ipv4.tcp_rmem=4096 32768 262142 net.ipv4.tcp_wmem=4096 32768 262142 net.core.netdev_max_backlog= 8096 net.core.rmem_default=262144 net.core.wmem_default= 262144net.core.rmem_max=2097152 net.core.wmem_max=2097152 net.ipv4.tcp_syncookies=1 net.ipv4.tcp_max_syn.backlog=1024
Parameter description:
File-MAX: this parameter indicates that a process (such as a worker process) can be opened at the same time.Max handle countThis parameter directly limits the maximum number of concurrent connections, which must be configured according to the actual situation.
Tcp_tw_reuse: this parameter is set to 1, which indicates that the socket in the Time-Wait status can be re-applied to the new TCP connection, which makes sense for the server, because there are always a lot of time-Wait connections on the server.
Tcp_keepalive_time: indicates the frequency of keepalive messages sent by TCP when keepalive is enabled. The default value is 2 hours. If you set it to a smaller value, you can clear invalid connections faster.
Tcp_fin_timeout: the maximum time for the socket to remain in the fin-wait-2 state when the server closes the connection.
Tcp_max_tw_buckets: this parameter indicates the maximum number of time_wait sockets allowed by the operating system. If this number is exceeded, time_wait socket is immediately cleared and warning information is printed. The default value of this parameter is 180000. Too many time_wait sockets will slow the Web server down.
Tcp_max_syn_backlog: this parameter indicates the maximum length of the SYN Request queue received during the TCP three-way handshake establishment phase. The default value is 1024. setting this parameter to a greater value may cause nginx to be too busy to access the new connection, linux does not lose connection requests initiated by clients.
Ip_local_port_range: this parameter defines local connections in UDP and TCP connections (excluding remote connections)Port value range.
Net. ipv4.tcp _ rmem: this parameter definesTCP receiving CacheThe minimum value, default value, and maximum value of the TCP receiving sliding window.
Net. ipv4.tcp _ WMEM: this parameter definesTCP sending CacheThe minimum value, default value, and maximum value of the TCP transmission sliding window.
Netdev_max_backlog: when the speed at which the network adapter receives data packets is greater than that processed by the kernel, a queue stores these data packets. This parameter indicatesMaximum queue Value.
Rmem _ default: the default size of the buffer area received by the kernel socket.
WMEM _ default: the default size of the kernel socket sending cache.
Rmem _ max: the maximum size of the buffer area received by the kernel socket.
WMEM _ max: the maximum size of the buffer area sent by the kernel socket.
Nginx installation Configuration