Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • gzip
  • gzip_buffers
  • gzip_comp_level
  • gzip_disable
  • gzip_min_length
  • gzip_http_version
  • gzip_proxied
  • gzip_types
  • gzip_vary
  • 内嵌变量
  • 原文档
  1. 核心功能
  2. HTTP

ngx_http_gzip_module

上一页ngx_http_gunzip_module下一页ngx_http_gzip_static_module

最后更新于5年前

ngx_http_gzip_module 模块是一个使用了 gzip 方法压缩响应的过滤器。有助于将传输数据的大小减少一半甚至更多。

示例配置

gzip            on;
gzip_min_length 1000;
gzip_proxied    expired no-cache no-store private auth;
gzip_types      text/plain application/xml;

$gzip_ratio 变量可用于记录实现的压缩比率。

指令

gzip

-

说明

语法

gzip on | off;

默认

gzip off;

上下文

http、server、location、location 中的 if

启用或禁用响应的 gzip 压缩。

gzip_buffers

-

说明

语法

gzip_buffers number size;

默认

gzip_buffers 32 4k|16 8k;

上下文

http、server、location

设置用于压缩响应的缓冲区的数量(number)和大小(size)。默认情况下,缓冲区大小等于一个内存页(4K 或 8K,取决于平台)。

在 0.7.28 版本之前,默认使用 4 个 4K 或 8K 缓冲区。

gzip_comp_level

-

说明

语法

gzip_comp_level level;

默认

gzip_comp_level 1;

上下文

http、server、location

设置响应的 gzip 压缩级别(level)。值的范围为 1 到 9。

gzip_disable

-

说明

语法

gzip_disable regex ...;

默认

——

上下文

http、server、location

提示

该指令在 0.6.23 版本中出现

禁用对与任何指定正则表达式匹配的 User-Agent 头字段的请求响应做 gzip 处理。

特殊掩码 msie6(0.7.12)对应正则表达式 MSIE [4-6]\.,但效率更高。从 0.8.11 版本开始,MSIE 6.0; ... SV1 不包含在此掩码中。

gzip_min_length

-

说明

语法

gzip_min_length length;

默认

gzip_min_length 20;

上下文

http、server、location

设置被压缩响应的最小长度。该长度仅由 Content-Length 响应头字段确定。

gzip_http_version

-

说明

语法

gzip_http_version 1.0 | 1.1;

默认

gzip_http_version 1.1;

上下文

http、server、location

设置压缩响应一个请求所需的最小 HTTP 版本。

gzip_proxied

-

说明

语法

gzip_proxied off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any ...;

默认

gzip_proxied off;

上下文

http、server、location

根据请求和响应,启用或禁用针对代理请求的响应的 gzip。事实上请求被代理取决于 Via 请求头字段是否存在。该指令接受多个参数:

  • off

    禁用所有代理请求压缩,忽略其他参数

  • expired

    如果响应头包含 Expires” 字段并且其值为禁用缓存,则启用压缩

  • no-cache

    如果响应头包含具有 no-cache 参数的 Cache-Control 字段,则启用压缩

  • no-store

    如果响应头包含具有 no-store 参数的 Cache-Control 字段,则启用压缩

  • private

    如果响应头包含带有 private 参数的 Cache-Control 字段,则启用压缩

  • no_last_modified

    如果响应头不包含 Last-Modified 字段,则启用压缩

  • no_etag

    如果响应头不包含 ETag 字段,则启用压缩

  • auth

    如果请求头包含 Authorization 字段,则启用压缩

  • any

    为所有代理请求启用压缩

gzip_types

-

说明

语法

gzip_types mime-type ...;

默认

gzip_types text/html;

上下文

http、server、location

除了 text/html 之外,还可以针对指定的 MIME 类型启用 gzip 响应。特殊值 * 匹配任何 MIME 类型(0.8.29)。对 text/html 类型的响应始终启用压缩。

gzip_vary

-

说明

语法

gzip_vary on | off;

默认

gzip_vary off;

上下文

http、server、location

内嵌变量

  • $gzip_ratio

    实现压缩比率,计算为原始压缩响应大小与压缩后响应大小之间的比率。

原文档

如果指令 、 或 处于激活状态,则启用或禁用插入 Vary:Accept-Encoding 响应头字段。

http://nginx.org/en/docs/http/ngx_http_gzip_module.html
指令
gzip
gzip_buffers
gzip_comp_level
gzip_disable
gzip_min_length
gzip_http_version
gzip_proxied
gzip_types
gzip_vary
内嵌变量
gzip
gunzip
gzip_static