Configuring Nginx achieve connection timeout
In corporate website in order to avoid prolonged occupation with a client connection, waste of resources, you can set the appropriate connection timeout parameters to achieve control connection access time.
1. "curl -I" command to view the connection parameters
[root@localhost nginx]# curl -I 192.168.52.131
HTTP/1.1 200 OK
Server: nginx/1.1.1
Date: Wed, 13 Nov 2019 11:06:54 GMT
Content-Type: text/html
Content-Length: 637
Last-Modified: Wed, 13 Nov 2019 08:09:06 GMT
Connection: keep-alive //无超时时间
ETag: "5dcbba22-27d"
Accept-Ranges: bytes
2. Modify the nginx configuration file
[root@localhost nginx]# vim conf/nginx.conf
keepalive_timeout 65 180; //连接保持超时时间,65为服务端超时时间,180为客户端超时时间,单位秒
client_header_timeout 80; //等待客户端发送请求头部的超时时间
client_body_timeout 80; //请求体读超时时间
[root@localhost nginx]# service nginx restart //重启服务
[root@localhost nginx]#
3. again with "curl -I" command to view the connection parameters
[root@localhost nginx]# curl -I 192.168.52.131
HTTP/1.1 200 OK
Server: nginx/1.1.1
Date: Wed, 13 Nov 2019 11:08:28 GMT
Content-Type: text/html
Content-Length: 637
Last-Modified: Wed, 13 Nov 2019 08:09:06 GMT
Connection: keep-alive
Keep-Alive: timeout=180 //超时时间
ETag: "5dcbba22-27d"
Accept-Ranges: bytes
[root@localhost nginx]#