Nginx optimizes Web Server Linux Kernel Parameters

Source: Internet
Author: User
Linux Kernel Parameter Adjustment is essential when Nginx provides web services. We need to pay special attention to the optimization. The following is a detailed introduction to Linux Kernel Parameter optimization. Linux Kernel Parameter Optimization: the number of net. ipv4.tcp _ max_tw_buckets6000timewait instances. The default value is 180000. Ne

Linux Kernel Parameter Adjustment is essential when Nginx provides web services. We need to pay special attention to the optimization. The following is a detailed introduction to Linux Kernel Parameter optimization.

Linux Kernel Parameter Optimization:

Net. ipv4.tCp_ Max_tw_buckets = 6000

TimeThe number of wait instances. The default value is 180000.

Net. ipv4.ip _ local_port_range = 1024 65000

Port range that can be opened by the system.

Net. ipv4.tcp _ tw_recycle = 1

Enable timewait quick recovery.

Net. ipv4.tcp _ tw_reuse = 1

Enable reuse. Allow TIME-WAIT sockets to be re-used for a New TCP connection.

Net. ipv4.tcp _ syNcOokies = 1

Enable SYN Cookies. When a SYN wait queue overflow occurs, enable cookies for processing.

Net. core. somaxconn = 262144

By default, the backlog of the listen function in the web application limits the net. core. somaxconn of kernel parameters to 128, while the NGX_LISTEN_BACKLOG defined by Nginx kernel parameters is 511 by default, so it is necessary to adjust this value.

Net. core. netdev_max_backlog = 262144

The maximum number of packets that can be sent to the queue when each network interface receives packets faster than the kernel processes these packets.

Net. ipv4.tcp _ max_orphans = 262144

The maximum number of TCP sockets in the system is not associated with any user file handle. If this number is exceeded, the orphan connection is immediately reset and a warning is printed. This limit is only used to prevent simple DoS attacks. You cannot rely too much on it or artificially reduce the value. You should also increase this value (if the memory is increased ).

Net. ipv4.tcp _ max_syn_backlog = 262144

The maximum number of connection requests that have not received confirmation from the client. For systems with 1024 MB of memory, the default value is 128, while for systems with small memory, the value is.

Net. ipv4.tcp _ timestamps = 0

Timestamp can avoid serial number winding. A 1 Gbit/s link must have a previously used serial number. The timestamp allows the kernel to accept such "abnormal" packets. Disable it here.

Net. ipv4.tcp _ synack_reTrIes = 1

To enable the peer connection, the kernel needs to send a SYN with an ACK that responds to the previous SYN. That is, the second handshake in the three-way handshake. This setting determines the number of SYN + ACK packets sent before the kernel disconnects.

Net. ipv4.tcp _ syn_retries = 1

Number of SYN packets sent before the kernel disconnects the connection.

Net. ipv4.tcp _ fin_timeout = 1

If the socket is disabled by the local end, this parameter determines the time it remains in the FIN-WAIT-2 state. The peer can make an error and never close the connection, or even become an unexpected machine. The default value is 60 seconds. 2.2 The kernel value is usually 180 seconds. You can follow this setting, but remember that even if your machine is a lightweight WEB server, there is also a risk of memory overflow due to a large number of dead sockets. The risk of FIN-WAIT-2 is smaller than that of FIN-WAIT-1, because it can only eat K of memory at most, however, they have a longer lifetime.

Net. ipv4.tcp _ keepalive_time = 30

The frequency of keepalive messages sent by TCP when keepalive is in use. The default value is 2 hours.

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.