FAQ

Page Discussion Edit History

ChsHttpGzipModule

Nginx涓枃鏂囨。 > 鍩烘湰妯″潡 > ngx_http_gzip_module

杩欎釜妯″潡鏀寔鍦ㄧ嚎瀹炴椂鍘嬬缉杈撳嚭鏁版嵁娴

__浣跨敤鑼冧緥__

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

鍐呯疆鍙橀噺 $gzip_ratio 鍙互鑾峰彇鍒癵zip鐨勫帇缂╂瘮鐜

Contents

[edit] 鎸囦护

  • [#gzip gzip]
  • [#gzip_buffers gzip_buffers]
  • [#gzip_comp_level gzip_comp_level]
  • [#gzip_min_length gzip_min_length]
  • [#gzip_http_version gzip_http_version]
  • [#gzip_proxied gzip_proxied]
  • [#gzip_types gzip_types]

Template:Anchor

[edit] gzip

璇硶: gzip on|off

榛樿鍊: gzip off

浣滅敤鍩: http, server, location, if (x) location

寮鍚垨鑰呭叧闂璯zip妯″潡

Template:Anchor

[edit] gzip_buffers

璇硶: gzip_buffers number size

榛樿鍊: gzip_buffers 4 4k/8k

浣滅敤鍩: http, server, location


璁剧疆绯荤粺鑾峰彇鍑犱釜鍗曚綅鐨勭紦瀛樼敤浜庡瓨鍌╣zip鐨勫帇缂╃粨鏋滄暟鎹祦銆 渚嬪 4 4k 浠h〃浠4k涓哄崟浣嶏紝鎸夌収鍘熷鏁版嵁澶у皬浠4k涓哄崟浣嶇殑4鍊嶇敵璇峰唴瀛樸 4 8k 浠h〃浠8k涓哄崟浣嶏紝鎸夌収鍘熷鏁版嵁澶у皬浠8k涓哄崟浣嶇殑4鍊嶇敵璇峰唴瀛樸

濡傛灉娌℃湁璁剧疆锛岄粯璁ゅ兼槸鐢宠璺熷師濮嬫暟鎹浉鍚屽ぇ灏忕殑鍐呭瓨绌洪棿鍘诲瓨鍌╣zip鍘嬬缉缁撴灉銆


Template:Anchor

[edit] gzip_comp_level

璇硶: gzip_comp_level 1..9

榛樿鍊: gzip_comp_level 1

浣滅敤鍩: http, server, location

gzip鍘嬬缉姣旓紝1 鍘嬬缉姣旀渶灏忓鐞嗛熷害鏈蹇紝9 鍘嬬缉姣旀渶澶т絾澶勭悊鏈鎱紙浼犺緭蹇絾姣旇緝娑堣梒pu锛夈

Template:Anchor

[edit] gzip_min_length

璇硶: gzip_min_length length

榛樿鍊: gzip_min_length 0

浣滅敤鍩: http, server, location


璁剧疆鍏佽鍘嬬缉鐨勯〉闈㈡渶灏忓瓧鑺傛暟锛岄〉闈㈠瓧鑺傛暟浠巋eader澶翠腑鐨凜ontent-Length涓繘琛岃幏鍙栥

榛樿鍊兼槸0锛屼笉绠¢〉闈㈠澶ч兘鍘嬬缉銆

寤鸿璁剧疆鎴愬ぇ浜1k鐨勫瓧鑺傛暟锛屽皬浜1k鍙兘浼氳秺鍘嬭秺澶с 鍗: gzip_min_length 1024

Template:Anchor

[edit] gzip_http_version

璇硶: gzip_http_version 1.0|1.1

榛樿鍊: gzip_http_version 1.1

浣滅敤鍩: http, server, location

璇嗗埆http鐨勫崗璁増鏈傜敱浜庢棭鏈熺殑涓浜涙祻瑙堝櫒鎴栬卙ttp瀹㈡埛绔紝鍙兘涓嶆敮鎸乬zip鑷В鍘嬶紝鐢ㄦ埛灏变細鐪嬪埌涔辩爜锛屾墍浠ュ仛涓浜涘垽鏂繕鏄湁蹇呰鐨勩 娉細21涓栫邯閮芥潵浜嗭紝鐜板湪闄や簡绫讳技浜庣櫨搴︾殑铚樿洓涔嬬被鐨勪笢瑗夸笉鏀寔鑷В鍘嬶紝99.99%鐨勬祻瑙堝櫒鍩烘湰涓婇兘鏀寔gzip瑙e帇浜嗭紝鎵浠ュ彲浠ヤ笉鐢ㄨ杩欎釜鍊,淇濇寔绯荤粺榛樿鍗冲彲銆


Template:Anchor

[edit] gzip_proxied

璇硶: gzip_proxied [off|expired|no-cache|no-store|private|no_last_modified|no_etag|auth|any] ...

榛樿鍊: gzip_proxied off

浣滅敤鍩: http, server, location

Nginx浣滀负鍙嶅悜浠g悊鐨勬椂鍊欏惎鐢紝寮鍚垨鑰呭叧闂悗绔湇鍔″櫒杩斿洖鐨勭粨鏋滐紝鍖归厤鐨勫墠鎻愭槸鍚庣鏈嶅姟鍣ㄥ繀椤昏杩斿洖鍖呭惈"Via"鐨 header澶淬

  • off - 鍏抽棴鎵鏈夌殑浠g悊缁撴灉鏁版嵁鐨勫帇缂
  • expired - 鍚敤鍘嬬缉锛屽鏋渉eader澶翠腑鍖呭惈 "Expires" 澶翠俊鎭
  • no-cache - 鍚敤鍘嬬缉锛屽鏋渉eader澶翠腑鍖呭惈 "Cache-Control:no-cache" 澶翠俊鎭
  • no-store - 鍚敤鍘嬬缉锛屽鏋渉eader澶翠腑鍖呭惈 "Cache-Control:no-store" 澶翠俊鎭
  • private - 鍚敤鍘嬬缉锛屽鏋渉eader澶翠腑鍖呭惈 "Cache-Control:private" 澶翠俊鎭
  • no_last_modified - 鍚敤鍘嬬缉,濡傛灉header澶翠腑涓嶅寘鍚 "Last-Modified" 澶翠俊鎭
  • no_etag - 鍚敤鍘嬬缉 ,濡傛灉header澶翠腑涓嶅寘鍚 "ETag" 澶翠俊鎭
  • auth - 鍚敤鍘嬬缉 , 濡傛灉header澶翠腑鍖呭惈 "Authorization" 澶翠俊鎭
  • any - 鏃犳潯浠跺惎鐢ㄥ帇缂


Template:Anchor

[edit] gzip_types

璇硶: gzip_types mime-type [mime-type ...]

榛樿鍊: gzip_types text/html

浣滅敤鍩: http, server, location

鍖归厤MIME绫诲瀷杩涜鍘嬬缉锛岋紙鏃犺鏄惁鎸囧畾锛"text/html"绫诲瀷鎬绘槸浼氳鍘嬬缉鐨勩


娉ㄦ剰锛氬鏋滀綔涓篽ttp server鏉ヤ娇鐢紝涓婚厤缃枃浠朵腑瑕佸寘鍚枃浠剁被鍨嬮厤缃枃浠

http
{
	include       conf/mime.types;
	......
}


濡傛灉浣犲笇鏈涘帇缂╁父瑙勭殑鏂囦欢绫诲瀷锛屽彲浠ュ啓鎴愯繖涓牱瀛

http 
{
: include       conf/mime.types;

: gzip on;
: gzip_min_length  1000;
: gzip_buffers     4 8k;   
: gzip_http_version 1.1; 
: gzip_types       text/plain application/x-javascript text/css text/html application/xml;

: ......	
}

[edit] References

鍘熷鏂囨。