NGINX kernel parameter optimization

Source: Internet
Author: User
: This article mainly introduces NGINX kernel parameter optimization. if you are interested in the PHP Tutorial, you can refer to it. Kernel parameters are optimized mainly for Nginx applications in linux.
The following is an optimization example for your reference.
Net. ipv4.tcp _ max_tw_buckets = 6000
Net. ipv4.ip _ local_port_range = 1024 65000
Net. ipv4.tcp _ tw_recycle = 1
Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ syncookies = 1
Net. core. somaxconn = 262144
Net. core. netdev_max_backlog = 262144
Net. ipv4.tcp _ max_orphans = 262144
Net. ipv4.tcp _ max_syn_backlog = 262144
Net. ipv4.tcp _ synack_retries = 1
Net. ipv4.tcp _ syn_retries = 1
Net. ipv4.tcp _ fin_timeout = 1
Net. ipv4.tcp _ keepalive_time = 30
Add the preceding kernel parameter value to the/etc/sysctl. conf file, and then execute the following command to make it take effect.
/Sbin/sysctl-p
The preceding parameters are described as follows:
Net. ipv4.tcp _ max_tw_buckets is used to set the default value of timewait to 180000.
Net. ipv4.ip _ local_port_range is used to set the minimum port range that allows the system to open 1024
Net. ipv4.tcp _ tw_recycle is used to set the start timewait quick recovery.
Net. ipv4.tcp _ tw_reuse is used to enable reuse and allow time-wait sockets to be re-used for new tcp connections.
Net. ipv4.tcp _ syncookies are used to enable syn cookies. when syn waits for a queue, cookies are enabled.
Net. core. somaxconn is 128 by default. the parameter is used to adjust the number of tcp connections initiated by the system at the same time. in highly concurrent requests, the default value may cause connection timeout or retransmission. therefore, this value must be adjusted based on the number of concurrent requests.
Net. core. netdev_max_backlog indicates the maximum number of packets that can be sent to the queue when each network interface receives packets at a rate faster than the rate at which the kernel processes these packets.
Net. ipv4.tcp _ max_orphans is used to set the maximum number of tcp sockets in the system that are not associated with any user file handle. If this number is exceeded, the isolated connection is reset immediately and a warning is printed. This restriction is used to prevent simple DOS attacks. You cannot rely too much on this limit or even manually reduce this value. in more cases, you should increase this value.
Net. ipv4.tcp _ max_syn_backlog is used to record the maximum value of connection requests that have not received confirmation from the client. For systems with 1024 MB of memory, the default value of the sub-parameter is 128, and that of systems with small memory is.
The value of the net. ipv4.tcp _ synack_retries parameter determines the number of SYN + ACK packets sent before the kernel disconnects.
Net. ipv4.tcp _ syn_retries indicates the number of SYN packets sent before the kernel disconnects the resume connection.
Net. ipv4.tcp _ fin_timeout determines the time for the socket to remain in the FIN-WAIT-2 state. The default value is 60 seconds. It is very important to set this value correctly. sometimes, even if a web server with a small load has a large number of dead sockets, leading to the risk of memory overflow.
Net. ipv4.tcp _ keepalive_time indicates the frequency of keepalive messages sent by tcp when keepalive is started. The default value is 2 (in hours ).

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above describes the NGINX kernel parameter optimization, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.

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.