配置Nginx實現連接超時
在企業網站中,爲了避免同一個客戶長時間佔用連接,造成資源浪費,可設置相應的連接超時參數,實現控制連接訪問時間。
1.用“curl -I”命令查看connection參數
[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.修改nginx配置文件
[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.再次用“curl -I”命令查看connection參數
[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]#