{"id":1344,"date":"2023-03-19T09:49:01","date_gmt":"2023-03-19T01:49:01","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1344"},"modified":"2023-04-29T09:05:37","modified_gmt":"2023-04-29T01:05:37","slug":"nginx-config-gzip","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/19\/nginx-config-gzip\/","title":{"rendered":"Nginx\u914d\u7f6egzip\u4e2d\u7684\u5751"},"content":{"rendered":"<p>\u5728web\u670d\u52a1\u7aef\u5f00\u542fgzip\u538b\u7f29\u540e\uff0c\u80fd\u591f\u6709\u6548\u538b\u7f29\u6587\u4ef6\uff0c\u964d\u4f4e\u4f20\u8f93\u4f53\u79ef\uff0c\u4ee5\u8fbe\u5230\u51cf\u5c11\u4f20\u8f93\u65f6\u95f4\u3002<\/p>\n<p>nginx\u4e2d\u5f00\u542f\u914d\u7f6e\u5982\u4e0b\uff08\u53ef\u4ee5\u4f5c\u7528\u4e8e<code>http<\/code>\u3001<code>server<\/code>\u3001<code>location<\/code>\u5757\u4e2d\uff09\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code>gzip on;\ngzip_min_length 1k;  #gzip\u5f00\u542f\u9608\u503c\uff0c\u8d85\u8fc71k\u624d\u4f1a\u4f7f\u7528gzip\ngzip_buffers 4 16k;\n#gzip_http_version 1.0;  #gzip\u652f\u6301http\u534f\u8bae\ngzip_comp_level 2;  #\u538b\u7f29\u7ea7\u522b\uff0c\u8d8a\u9ad8\u538b\u7f29\u6bd4\u8d8a\u5927\uff0c\u8d8a\u6d88\u8017cpu\ngzip_types text\/plain application\/x-javascript application\/javascript text\/css application\/xml text\/javascript application\/x-httpd-php image\/jpeg image\/gif image\/png;  #\u652f\u6301\u6587\u4ef6\u7c7b\u578b<\/code><\/pre>\n<p>\u5b58\u5728\u7684\u5751\uff1a<\/p>\n<p>\uff081\uff09\u5982\u679cnginx\u4e2d\u4f7f\u7528\u4e86\u591a\u5c42\u4ee3\u7406\uff0c\u5219\u9700\u8981\u5c06<code>gzip_http_version 1.0<\/code>\u914d\u7f6e\u9879\u5f00\u542f\uff0c\u5426\u5219gzip\u914d\u7f6e\u4e0d\u8d77\u4f5c\u7528<\/p>\n<p>\u539f\u56e0\u5206\u6790\uff1a\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5f53\u524d\u6d4f\u89c8\u5668\u4e2d\u4f7f\u7528\u7684http\u534f\u8bae\u57fa\u672c\u4e0a\u662f1.1\u7248\u672c\uff0c\u800cnginx\u7684upstream\u901a\u4fe1\u534f\u8bae\u9ed8\u8ba4\u662fhttp\/1.0\uff0c<code>gzip_http_version<\/code>\u7684\u9ed8\u8ba4\u503c\u662f1.1\uff1b\u56e0\u6b64\u5982\u679c\u914d\u7f6e\u591a\u5c42\u4ee3\u7406\u65f6\uff0c\u5982\u679c\u6ca1\u6709\u914d\u7f6e<code>gzip_http_version<\/code>\u65f6\uff0c\u8be5\u503c\u9ed8\u8ba4\u4e3a1.1\uff0c\u800cagent nginx\u4f1a\u628a\u8bf7\u6c42\u8f6c\u5316\u4e3a1.0\u7248\u672c\u7684\uff0c\u6b64\u65f6gzip\u529f\u80fd\u5c31\u4f1a\u4e0d\u8d77\u4f5c\u7528\uff1b\u5c06<code>gzipz_http_version<\/code>\u914d\u7f6e\u4e3a1.0\u540e\uff0cgzip\u529f\u80fd\u6b63\u5e38\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/user-gold-cdn.xitu.io\/2018\/11\/20\/16731a523fe315b2?imageslim\" alt=\"Nginx\u53cd\u5411\u4ee3\u7406\" \/><\/p>\n<p>\uff082\uff09gzip_static<\/p>\n<p>\u5728\u5f00\u59cb\u538b\u7f29\u521b\u5efa\u786c\u76d8\u4e0a\u7684\u6587\u4ef6\u4e4b\u524d\uff0c\u672c\u6a21\u5757\u5c06\u67e5\u627e\u540c\u76ee\u5f55\u4e0b\u540c\u540d\u7684.gz\u538b\u7f29\u6587\u4ef6\uff0c\u4ee5\u907f\u514d\u540c\u4e00\u6587\u4ef6\u518d\u6b21\u538b\u7f29\u3002<\/p>\n<p>\u8fd9\u4e2a\u6a21\u5757\u4e0d\u662f\u9ed8\u8ba4\u7f16\u8bd1\u7684\uff0c\u56e0\u6b64\u9700\u8981\u6307\u5b9a<code>--with-http_gzip_static_module<\/code>\u7f16\u8bd1\u9009\u9879\u3002<\/p>\n<p>\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>gzip_static on;\n\ngzip_http_version   1.1;\ngzip_proxied        expired no-cache no-store private auth;\ngzip_disable        &quot;MSIE [1-6]\\.&quot;;\n\ngzip_vary           on;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728web\u670d\u52a1\u7aef\u5f00\u542fgzip\u538b\u7f29\u540e\uff0c\u80fd\u591f\u6709\u6548\u538b\u7f29\u6587\u4ef6\uff0c\u964d\u4f4e\u4f20\u8f93\u4f53\u79ef\uff0c\u4ee5\u8fbe\u5230\u51cf\u5c11\u4f20\u8f93\u65f6\u95f4\u3002 nginx\u4e2d\u5f00\u542f\u914d\u7f6e\u5982 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[332],"tags":[107],"class_list":["post-1344","post","type-post","status-publish","format-standard","hentry","category-nginx","tag-gzip"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1344"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1344\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}