{"id":1343,"date":"2023-03-19T09:46:33","date_gmt":"2023-03-19T01:46:33","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1343"},"modified":"2023-04-29T09:05:47","modified_gmt":"2023-04-29T01:05:47","slug":"nginx-config-gzip-compression","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/19\/nginx-config-gzip-compression\/","title":{"rendered":"Nginx\u914d\u7f6egzip\u538b\u7f29"},"content":{"rendered":"<p>Nginx\u5f00\u542fGzip\u53ef\u4ee5\u538b\u7f29\u5927\u5e45\u63d0\u9ad8\u9875\u9762\u52a0\u8f7d\u901f\u5ea6\u3002\u5f00\u542fnginx gzip\u538b\u7f29\u540e\uff0c\u7f51\u9875\u3001css\u3001js\u7b49\u9759\u6001\u8d44\u6e90\u7684\u5927\u5c0f\u4f1a\u5927\u5927\u7684\u51cf\u5c11\uff0c\u4ece\u800c\u53ef\u4ee5\u8282\u7ea6\u5927\u91cf\u7684\u5e26\u5bbd\uff0c\u63d0\u9ad8\u4f20\u8f93\u6548\u7387\uff0c\u7ed9\u7528\u6237\u5feb\u7684\u4f53\u9a8c\uff0c\u4f46\u662f\u4f1a\u6d88\u8017\u66f4\u591a\u7684cpu\u8d44\u6e90\u3002<\/p>\n<h2>Nginx\u914d\u7f6e<\/h2>\n<p><!-- more --><\/p>\n<pre><code>http {\n  #\u5f00\u542fGzip\n  gzip on;\n  #\u4e0d\u538b\u7f29\u4e34\u754c\u503c\uff0c\u5927\u4e8e100K\u7684\u624d\u538b\u7f29\uff0c\u8fd9\u4e2a\u6309\u9700\u6539\uff0c\u538b\u7f29\u8981\u6d88\u8017cpu\u8d44\u6e90\n  gzip_min_length 1k;\n  #\u538b\u7f29\u5728\u5185\u5b58\u4e2d\u7f13\u51b2\u51e0\u5757? \u6bcf\u5757\u591a\u5927?\n  gzip_buffers 4 16k;\n  #\u9ed8\u8ba4\u662fHTTP\/1.1\uff0c\u4f7f\u7528\u53cd\u5411\u4ee3\u7406\u65f6\uff0c\u672b\u7aef\u901a\u4fe1\u662fHTTP\/1.0\n  gzip_http_version 1.0;\n  #\u538b\u7f29\u7ea7\u522b\uff0c1-10\uff0c\u6570\u5b57\u8d8a\u5927\u538b\u7f29\u7684\u8d8a\u597d\uff0c\u65f6\u95f4\u4e5f\u8d8a\u957f\n  gzip_comp_level 2;\n  #\u8fdb\u884c\u538b\u7f29\u7684\u6587\u4ef6\u7c7b\u578b\n  gzip_types text\/plain application\/javascript application\/x-javascript application\/css text\/css application\/xml text\/javascript application\/x-httpd-php image\/jpeg image\/gif image\/png;\n  #\u4e3aon\u65f6\u4f1a\u5728Header\u91cc\u589e\u52a0&quot;Vary: Accept-Encoding&quot;\n  gzip_vary off;\n  #\u5ffd\u7565IE6\u53ca\u4ee5\u4e0b\n  gzip_disable &quot;MSIE [1-6]\\.&quot;;\n\n  server {\n\n  }\n}<\/code><\/pre>\n<p>\u6d4b\u8bd5\u547d\u4ee4<\/p>\n<pre><code>curl -I -H &quot;Accept-Encoding: gzip, deflate&quot; &quot;http:\/\/xxx.xxx.xxx.xxx:8080\/vendor.js&quot;<\/code><\/pre>\n<p>\u6d4b\u8bd5\u7ed3\u679c\uff1a\u5728\u54cd\u5e94Header\u4e2d\u9700\u8981\u51fa\u73b0<code>Content-Encoding: gzip<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx\u5f00\u542fGzip\u53ef\u4ee5\u538b\u7f29\u5927\u5e45\u63d0\u9ad8\u9875\u9762\u52a0\u8f7d\u901f\u5ea6\u3002\u5f00\u542fnginx gzip\u538b\u7f29\u540e\uff0c\u7f51\u9875\u3001css\u3001js\u7b49\u9759\u6001\u8d44 [&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-1343","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\/1343","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=1343"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1343\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}