30 Nginx的http块其他的配置指令说明

30 Nginx的http块其他的配置指令说明

30.1 sendfile

sendfile:用来设置Nginx服务器是否使用 sendfile() 函数传输文件,该属性可以提高Nginx 处理静态资源的性能(本质是linux磁盘读写的性能)

语法 sendfile on|off;
默认值 sendfile off;
位置 http、server、location

 

 

 

 

30.2 keepalive_timeout

keepalive_timeout:设置长连接的超时时间(最后一个连接关闭后开始计时,即服务器端空闲超时时间)

  HTTP是一种无状态协议,客户端向服务端发送一个TCP请求,服务端响应完毕后断开连接(建联过程经过三次握手,四次挥手)

  如果客户端向服务端发送多个请求,每个请求都需要重新创建一次连接,效率相对来说比较低,使用 keepalive_timeout 模式,服务端在处理完一个请求后保持这个TCP连接的打开状态,若接收到来自这个客户端的其他请求,服务端就会复用这个未被关闭的连接,而无需重新创建一个新连接,从而提升效率,但是这个连接也不能一直保持,会因为连接过多,导致服务器的性能下降,因此可以设置一个超时时间

语法 keepalive_timeout time(默认秒);
默认值 keepalive_timeout 75s;
位置 http、server、location

 

 

 

 

30.3 keepalive_requests

keepalive_requests:设置一个 keep-alive 连接使用的次数

语法

keepalive_requests number;
默认值 keepalive_requests 100;
位置 http、server、location

 

 

 

 

30.4 小结

[root@nginx-100 /usr/local/nginx/conf]# cat nginx.conf
..........
http {
..........
    sendfile        on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    keepalive_requests 100;
..........
[root@nginx-100 /usr/local/nginx/conf]# ../sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx-100 /usr/local/nginx/conf]# ../sbin/nginx -s reload

———————————————————————————————————————————————————————————————————————————

                                                                                                                         无敌小马爱学习

posted on 2026-04-21 22:24  马俊南  阅读(11)  评论(0)    收藏  举报