温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx服务优化(五)设置连接超时

发布时间:2020-07-21 10:10:49 来源:网络 阅读:659 作者:wx5d2c2d660c282 栏目:系统运维

配置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]#
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI