配置Nginx实现连接超时
在企业网站中,为了避免同一个客户长时间占用连接,造成资源浪费,可设置相应的连接超时参数,实现控制连接访问时间。
1.用“curl -I”命令查看connection参数
[[email protected] 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配置文件
[[email protected] nginx]# vim conf/nginx.conf
keepalive_timeout 65 180; //连接保持超时时间,65为服务端超时时间,180为客户端超时时间,单位秒
client_header_timeout 80; //等待客户端发送请求头部的超时时间
client_body_timeout 80; //请求体读超时时间
[[email protected] nginx]# service nginx restart //重启服务
[[email protected] nginx]#
3.再次用“curl -I”命令查看connection参数
[[email protected] 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
[[email protected] nginx]#
原文地址:https://blog.51cto.com/14449541/2450895
时间: 2024-10-08 22:33:24