1、文件读取 sendfile
配置语法:sendfile on | off;
默认配置:off
配置路径:http,server,location,if in location
2、tcp_nopush
配置语法:tcp_nopush on | off;
默认配置:off
配置路径:http,server,location
作用:sendfile开启的情况下(才能使用),提高网络包的传输效率。开启此选项允许在Linux和FreeBSD 4.*上将响应头和正文的开始部分一起发送,一次性发送整个文件。
3、tcp_nodelay
配置语法:tcp_nodelay on | off;
默认配置:off
配置路径:http,server,location
作用:keepalive连接下,提高网络包的传输实时性。这个选项仅在将连接转变为长连接的时候才被启用,(译者注,在upstream发送响应到客户端时也会启用)
tcp_nodelay 和 tcp_nopush 的解释
4、gzip压缩
配置语法:gzip on | off;
默认配置:off
配置路径:http,server,location
作用:压缩传输
gzip版本
配置语法:gzip_http_version 1.0 | 1.1;
默认配置:1.1
配置路径:http,server,location
http_gzip_static_module - 预读gzip功能,预先读取服务器已经压缩好的gizp文件
http_gunzip_module - 应用支持gunzip的压缩方式
location / { gzip off;# 开启Gzip gzip_min_length 1k;# 不压缩临界值,大于1K的才压缩,一般不用改 gzip_buffers 4 16k;# 缓冲区大小 gzip_http_version 1.0; # gzip版本 gzip_comp_level 2;# 压缩级别,1-10,数字越大压缩的越好,时间也越长 gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 进行压缩的文件类型,缺啥补啥就行了,JavaScript有两种写法,最好都写上吧,总有人抱怨js文件没有压缩,其实多写一种格