keepalive_timeout;
定义客户端保持连接超时时长,0表示禁止长连接,默认为65s,建议使用15s即可。
在ngx_http_upstream_module中也有此项设置,是定义反向代理转发给后端服务器时的超时时间.
支持环境:http,server,location
keepalive_requests number;
定义一次长连接上所允许请求的资源的最大数量,默认为100
支持环境:http, server, location
keepalive_disable none | browser ...;
对哪种浏览器禁用长连接
支持环境:http, server, location
#1.设置长连接功能,其中第一个60为长连接的保持时间,第二个60为返回给客户端的响应报文中Keep-Alive:timeout字段的值 [root@nginx01 web1]# cat /etc/nginx/conf.d/virtualhost.conf server { listen 80; server_name www.nginx01.com; keepalive_requests 3; keepalive_timeout 60 60; location / { root /data/nginx/html/web1; index index.html; } #2.重启nginx服务 [root@nginx01 web1]# systemctl reload nginx.service #3.客户端测试 root@xuzhichao ~]# telnet www.nginx01.com 80 Trying 192.168.20.20... Connected to www.nginx01.com. Escape character is '^]'. GET / HTTP/1.1 <==输入请求的内容 HOST: www.nginx01.com <==输入请求报文HOST字段携带的域名 #响应头部信息 HTTP/1.1 200 OK Server: nginx/1.20.1 Date: Wed, 16 Jun 2021 13:55:20 GMT Content-Type: text/html Content-Length: 31 Last-Modified: Tue, 15 Jun 2021 15:27:29 GMT Connection: keep-alive Keep-Alive: timeout=60 <==为服务器端返回给客户端的值 ETag: "60c8c6e1-1f" Accept-Ranges: bytes www.nginx01.com <==页面内容 Connection closed by foreign host.