Module ngx_http_gzip_module
Example Configuration
Directives
[gzip]
[gzip_buffers]
[gzip_comp_level]
[gzip_disable]
[gzip_min_length]
[gzip_http_version]
[gzip_proxied]
[gzip_types]
[gzip_vary]
[gzip_no_buffer] [Embedded Variables]
$gzip_ratio
Example Configuration
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/xml;
Directives
* gzip Syntax: gzip on | off; Default: gzip off; Context: http, server, location, if in location #是否啓用壓縮 * gzip_buffers Syntax: gzip_buffers number size; Default: gzip_buffers 32 4k|16 8k; Context: http, server, location #設置壓縮緩存的數量大小與 platform memory page 相關 #獲取系統緩存也大小: $getconf PAGE_SIZE * gzip_comp_level Syntax: gzip_comp_level level; Default: gzip_comp_level 1; Context: http, server, location #壓縮級別:1~9 1:壓縮最快,壓縮比小 9:最慢,壓縮比大,消耗CPU資源 * gzip_disable Syntax: gzip_disable regex ...; Default: — Context: http, server, location # regex匹配$User-Agent時不壓縮 * gzip_min_length Syntax: gzip_min_length length; Default: gzip_min_length 20; Context: http, server, location #最小壓縮長度 比較“$Conteng-Length” * gzip_http_version Syntax: gzip_http_version 1.0 | 1.1; Default: gzip_http_version 1.1; Context: http, server, location #此處強調wget http/1.0協議,curl http/1.1協議, 如果走默認version,wget 無法測試 需要指定gzip_http_version 1.0; 得到Content-Encoding:gzip 就沒有"Content_Length"響應頭 使用1.0版本,Keepalive 將無效; 使用1.1版本,chunked 傳遞處理; * gzip_proxied Syntax: gzip_proxied off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any ...; Default: gzip_proxied off; Context: http, server, location 根據請求 & 響應判斷時候支持響應壓縮,匹配$via 進行判斷 > off #拒絕壓縮所有代理請求 > expired #response head include expired && 且值爲不緩存 則壓縮 > no-cache #cache-control:no-cache 則壓縮 > no-store > private > no_last_modified #不含Last-Modified > no_etag #不含etag > auth #request include Authorizaton > any #任何代理請求都壓縮 * gzip_types Syntax: gzip_types mime-type ...; Default: gzip_types text/html; Context: http, server, location #已經包含text/html,空格分隔。 *:添加所有MIME類型 * gzip_vary Syntax: gzip_vary on | off; Default: gzip_vary off; Context: http, server, location #是否添加"Vary:Accept-Encoding" response_head (如果開啓導致IE4~6不緩存) # gzip_no_buffer Syntax: gzip_no_buffer on|off Default: off Context: http,server,location #默認ngx返回client數據會進行等待,直到gzip_buffers填滿,開啓會禁用緩存
Embedded Variables
$gzip_ratio: 實現壓縮比,計算爲原始和壓縮響應大小的比值。