非常教程

Nginx参考手册

ngx_http_gzip_module

ngx_http_gzip_module

  • 示例配置
  • 指令
  • gzip
  • gzip_buffers
  • gzip_comp_level
  • gzip_disable
  • gzip_min_length
  • gzip_http_version
  • gzip_proxied
  • gzip_types
  • gzip_vary
  • 嵌入式变量

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 off;

语境:

http,服务器,位置,如果在指定位置

启用或禁用回应的gzip。

句法:

gzip_buffers数字大小;

默认:

gzip_buffers 32 4k | 16 8k;

语境:

http,服务器,位置

设置numbersize用于压缩的响应缓冲区。默认情况下,缓冲区大小等于一个内存页面。这是4K或8K,取决于平台。

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

句法:

gzip_comp_level level;

默认:

gzip_comp_level 1;

语境:

http,服务器,位置

设置level响应的gzip压缩。可接受的值在1到9的范围内。

句法:

gzip_disable正则表达式...;

默认:

语境:

http,服务器,位置

禁用具有与任何指定正则表达式匹配的“用户代理”标题字段的请求响应的gzip。

特殊掩码“ msie6”(0.7.12)对应于正则表达式“ MSIE [4-6]\.”,但工作更快。从版本0.8.11开始,“ MSIE 6.0; ... SV1”将从此掩码中排除。

句法:

gzip_min_length长度;

默认:

gzip_min_length 20;

语境:

http,服务器,位置

设置将被压缩的响应的最小长度。该长度仅由“Content-Length”响应标题字段确定。

句法:

gzip_http_version 1.0 | 1.1;

默认:

gzip_http_version 1.1;

语境:

http,服务器,位置

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

句法:

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

默认:

gzip_proxied off;

语境:

http,服务器,位置

取决于请求和响应,启用或禁用针对代理请求的响应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如果请求标题包含“授权”字段,则启用压缩; any为所有代理请求启用压缩。

句法:

gzip_types mime-type ...;

默认:

gzip_types text / html;

语境:

http,服务器,位置

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

句法:

gzip_vary开启| 关闭;

默认:

gzip_vary关闭;

语境:

http,服务器,位置

如果指令gzip,gzip_static或gunzip处于活动状态,则启用或禁用插入“Vary:Accept-Encoding”响应标头字段。

嵌入式变量

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

ngx_http_gzip_module
Nginx

Nginx是一款轻量级的 Web 服务器/反向代理服务器及电子邮件代理服务器,可在 BSD-like 协议下发行。其特点是占有内存少,并发能力强。

主页 https://nginx.org/
源码 http://hg.nginx.org/nginx
发布版本 1.13.6

Nginx目录

1.指南 | Guides
2.核心 | Core
3.ngx_google_perftools_module
4.ngx_http_access_module
5.ngx_http_addition_module
6.ngx_http_api_module
7.ngx_http_auth_basic_module
8.ngx_http_auth_jwt_module
9.ngx_http_auth_request_module
10.ngx_http_autoindex_module
11.ngx_http_browser_module
12.ngx_http_charset_module
13.ngx_http_core_module
14.ngx_http_dav_module
15.ngx_http_empty_gif_module
16.ngx_http_f4f_module
17.ngx_http_fastcgi_module
18.ngx_http_flv_module
19.ngx_http_geoip_module
20.ngx_http_geo_module
21.ngx_http_gunzip_module
22.ngx_http_gzip_module
23.ngx_http_gzip_static_module
24.ngx_http_headers_module
25.ngx_http_hls_module
26.ngx_http_image_filter_module
27.ngx_http_index_module
28.ngx_http_js_module
29.ngx_http_keyval_module
30.ngx_http_limit_conn_module
31.ngx_http_limit_req_module
32.ngx_http_log_module
33.ngx_http_map_module
34.ngx_http_memcached_module
35.ngx_http_mirror_module
36.ngx_http_mp4_module
37.ngx_http_perl_module
38.ngx_http_proxy_module
39.ngx_http_random_index_module
40.ngx_http_realip_module
41.ngx_http_referer_module
42.ngx_http_rewrite_module
43.ngx_http_scgi_module
44.ngx_http_secure_link_module
45.ngx_http_session_log_module
46.ngx_http_slice_module
47.ngx_http_spdy_module
48.ngx_http_split_clients_module
49.ngx_http_ssi_module
50.ngx_http_ssl_module
51.ngx_http_status_module
52.ngx_http_stub_status_module
53.ngx_http_sub_module
54.ngx_http_upstream_conf_module
55.ngx_http_upstream_hc_module
56.ngx_http_upstream_module
57.ngx_http_userid_module
58.ngx_http_uwsgi_module
59.ngx_http_v2_module
60.ngx_http_xslt_module
61.ngx_mail_auth_http_module
62.ngx_mail_core_module
63.ngx_mail_imap_module
64.ngx_mail_pop3_module
65.ngx_mail_proxy_module
66.ngx_mail_smtp_module
67.ngx_mail_ssl_module
68.ngx_stream_access_module
69.ngx_stream_core_module
70.ngx_stream_geoip_module
71.ngx_stream_geo_module
72.ngx_stream_js_module
73.ngx_stream_limit_conn_module
74.ngx_stream_log_module
75.ngx_stream_map_module
76.ngx_stream_proxy_module
77.ngx_stream_realip_module
78.ngx_stream_return_module
79.ngx_stream_split_clients_module
80.ngx_stream_ssl_module
81.ngx_stream_ssl_preread_module
82.ngx_stream_upstream_hc_module
83.ngx_stream_upstream_module