资讯专栏INFORMATION COLUMN

nginx gzip配置参数解读

付永刚 / 1282人阅读

本文主要解析一下nginx ngx_http_gzip_module以及ngx_http_gzip_static_module中的gzip相关配置参数。

gzip
名称 默认配置 作用域 官方说明 中文解读 模块
gzip gzip off; http, server, location, if in location Enables or disables gzipping of responses. 设置是否开启对后端响应的gzip压缩,然后返回压缩内容给前端 ngx_http_gzip_module
gzip_buffers gzip_buffers 32 4k或16 8k; http, server, location Sets the number and size of buffers used to compress a response. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform. 设置用于压缩后端response的buffer的数量和每个的大小,默认每个buffer大小为一个内存页,根据平台不同可能是4k或8k ngx_http_gzip_module
gzip_comp_level gzip_comp_level 1; http, server, location Sets a gzip compression level of a response. Acceptable values are in the range from 1 to 9. 指定gzip压缩的级别,默认为1,该值可设置的范围是1-9,1为最小化压缩(处理速度快),9为最大化压缩(处理速度慢),数字越大压缩的越好,也越占用CPU时间 ngx_http_gzip_module
gzip_disable 没有默认值 http, server, location Disables gzipping of responses for requests with User-Agent header fields matching any of the specified regular expressions. 正则匹配User-Agent中的值,匹配上则不进行gzip ngx_http_gzip_module
gzip_min_length gzip_min_length 20; http, server, location Sets the minimum length of a response that will be gzipped. The length is determined only from the Content-Length response header field. 设定进行gzip压缩的阈值,当后端response的Content-Length大小小于该值则不进行gzip压缩 ngx_http_gzip_module
gzip_http_version gzip_http_version 1.1; http, server, location Sets the minimum HTTP version of a request required to compress a response. 设定进行gzip压缩的最小http版本 ngx_http_gzip_module
gzip_proxied gzip_proxied off; http, server, location Enables or disables gzipping of responses for proxied requests depending on the request and response. The fact that the request is proxied is determined by the presence of the "Via" request header field. 根据request或响应的相关header的值来决定是否进行gzip ngx_http_gzip_module
gzip_types gzip_types text/html; http, server, location Enables gzipping of responses for the specified MIME types in addition to "text/html". The special value "*" matches any MIME type (0.8.29). Responses with the "text/html" type are always compressed. 指定哪些mime types启用gzip压缩,默认text/html ngx_http_gzip_module
gzip_vary gzip_vary off; http, server, location Enables or disables inserting the "Vary: Accept-Encoding" response header field if the directives gzip, gzip_static, or gunzip are active. 是否往response header里头写入Vary: Accept-Encoding ngx_http_gzip_module
gzip_static gzip_static off; http, server, location Enables ("on") or disables ("off") checking the existence of precompressed files. The following directives are also taken into account: gzip_http_version, gzip_proxied, gzip_disable, and gzip_vary. 开启之后,接到(静态文件)请求会到url相同的路径的文件系统去找扩展名为".gz"的文件,如果存在直接把它发送出去,如果不存在,则进行gzip压缩,再发送出去 ngx_http_gzip_static_module
实例
http {
    gzip on;
    gzip_buffers 8 16k; ## 这个限制了nginx不能压缩大于128k的文件
    gzip_comp_level 2;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    gzip_min_length 512; ##单位byte
    gzip_http_version 1.0;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types   text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_static  on;
    //......
}
doc

nngx_http_gzip_module

加速nginx: 开启gzip和缓存

mozilla Vary

HTTP 协议中 Vary 的一些研究

Nginx中gzip_static模块的使用

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39753.html

相关文章

  • nginx服务器安装及配置文件详解

    摘要:部分设置的指令将影响其它所有部分的设置部分的指令主要用于指定虚拟主机域名和端口的指令用于设置一系列的后端服务器,设置反向代理及后端服务器的负载均衡部分用于匹配网页位置比如,根目录等等。 nginx在工作中已经有好几个环境在使用了,每次都是重新去网上扒博客,各种编译配置,今天自己也整理一份安装文档和nginx.conf配置选项的说明,留作以后参考。像负载均衡配置(包括健康检查)、缓存(包...

    mylxsw 评论0 收藏0
  • 11 个 Nginx 参数性能优化工作

    摘要:配置如下指令是设定的工作模式及连接数上限。指令用来指定的工作模式。该参数默认是,建议开启。配置进程的最大打开文件数调整配置进程的最大打开文件数,这个控制连接数的参数为。但副作用是资源更新可能无法及时。 工作上,需要配置 Nginx,要投入生产使用,做了一点优化工作,加上以前也经常折腾 Nginx,故记下一些优化工作。 优化 Nginx 进程数量 配置参数如下: worker_proce...

    zebrayoung 评论0 收藏0
  • nginx配置中开启gzip来压缩网页文件提高网站速度

    摘要:如何开启来压缩网页文件提高网站速度要知道网站的打开速度取决于浏览器打开下载的网页文件大小。你可以在配置中开启来压缩网页文件。默认情况下,仅压缩文件。服务器上设置站点上设如何在中开启压缩服务让网页速度更快服务器设置压缩是开发里很普遍的做法。nginx如何开启gzip来压缩网页文件提高网站速度?要知道网站的打开速度取决于浏览器打开下载的网页文件大小。如果传输的页面内容文件减少,那你网站的打开速度...

    stonezhu 评论0 收藏0
  • 我用到的nginx

    摘要:有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。 查看nginx配置文件位置 方式11) netstat -anop | grep 0.0.0.0:80 查看nginx的pid2) ll /proc/4562/exe nginx运行的路径(比如查询到: /usr/sbin/nginx)3) /usr/sbin/ng...

    zhaofeihao 评论0 收藏0
  • 高并发场景中nginx的优化方案

    摘要:本文主要从以下几点讲解如何优化,以增强高并场景中的吞吐量。系统可通过命令查看核数,假如为,则指单个进程能并发处理的最大连接数,包含了所有的链接不仅仅来源于客户端,默认值是,在一些瞬间并发量较高的场景中,这个值是远远不够用的。 本文主要从以下几点讲解如何优化Nginx,以增强高并场景中Nginx的吞吐量。 调整worker_processes和worker_connections参数 ...

    EsgynChina 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<