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]#

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站标题:Nginx服务优化(五)设置连接超时-创新互联
当前链接:http://myzitong.com/article/diojid.html