Nginx服務優化(五)設置連接超時

配置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]#
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章