欢迎光临
我们一直在努力

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]#
赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。