WEB服务与NGINX(8)-NGINX的长连接功能
2021/6/20 7:26:54
本文主要是介绍WEB服务与NGINX(8)-NGINX的长连接功能,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. 长连接配置
-
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.
这篇关于WEB服务与NGINX(8)-NGINX的长连接功能的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29fail2ban nginx
- 2024-03-18install nginx proxy manager
- 2024-01-2444从零开始用Rust编写nginx,命令行参数的设计与解析及说明
- 2024-01-22比Nginx更好用的Gateway!
- 2024-01-17nginx daemon off
- 2023-12-30Nginx Vhost Traffic Status 是什么意思-icode9专业技术文章分享
- 2023-12-26使用nginx搭建creates.io镜像(稀疏索引)
- 2023-11-18centos7编译安装Nginx教程。
- 2023-11-02nginx启动命令和停止命令
- 2023-10-25Centos7系统Nginx负载均衡如何安装和配置?