{"id":3809,"date":"2019-01-28T17:56:02","date_gmt":"2019-01-28T09:56:02","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3809"},"modified":"2019-01-28T17:56:02","modified_gmt":"2019-01-28T09:56:02","slug":"nginx-%e5%bc%80%e5%90%af-gzip-%e5%8e%8b%e7%bc%a9","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3809","title":{"rendered":"Nginx \u5f00\u542f gzip \u538b\u7f29"},"content":{"rendered":"<p>\n\t\u524d\u9762\u6211\u5df2\u7ecf\u5199\u8fc7\u4e00\u7bc7 gzip \u7684\u6587\u7ae0\u6765\u505a\u94fa\u57ab\u4e86\u300a<a href=\"https:\/\/www.xttblog.com\/?p=3807\">Linux \u7684 gzip \u538b\u7f29<\/a>\u300b\u3002\u8fd9\u7bc7\u6587\u7ae0\u6211\u4eec\u5c31\u6765\u770b\u770b Nginx \u5982\u4f55\u5f00\u542f gzip \u538b\u7f29\u3002\n<\/p>\n<p>\n\tNginx \u4e2d\u5f00\u542f gzip \u538b\u7f29\u53ea\u9700\u8981 4 \u4e2a\u6b65\u9aa4\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Nginx \u4e2d\u5f00\u542f gzip \u538b\u7f29\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fzmfqzf4z6j20id034js3.jpg\" style=\"width: 661px;height: 112px\" \/>\n<\/p>\n<p>\n\t\u7b2c\u4e00\u6b65\uff0c\u914d\u7f6e gzip on\uff1b\u5f00\u542f gzip \u538b\u7f29\u3002\n<\/p>\n<p>\n\t\u7b2c\u4e8c\u6b65\uff0c\u914d\u7f6e gzip_comp_level 7; gzip \u538b\u7f29\u6bd4\uff0c\u9ed8\u8ba4\u662f\u538b\u7f29\u6bd4\u662f 6\u3002\n<\/p>\n<p>\n\t\u7b2c\u4e09\u6b65\uff0c\u914d\u7f6e gzip_min_length 1K; \u5141\u8bb8\u88ab\u538b\u7f29\u7684\u9875\u9762\u6700\u5c0f\u5b57\u8282\u6570\uff0c\u6839\u636e gzip \u7684\u539f\u7406\u53ef\u77e5\uff0c\u5e76\u4e0d\u5c11\u6240\u6709\u7684\u538b\u7f29\u6587\u4ef6\u6700\u540e\u90fd\u80fd\u53d8\u5c0f\u3002\u53e6\u5916\uff0c\u538b\u7f29\u9700\u8981\u6d88\u8017 CPU \u7684\uff0c\u4f60\u6587\u4ef6\u592a\u5c0f\uff0c\u6bd4\u5982\u4e00\u4e2a\u6570\u636e\u5305\u5c31\u80fd\u4f20\u8f93\u7684\uff0c\u538b\u7f29\u53cd\u800c\u6d6a\u8d39\u4e86 CPU \u8d44\u6e90\uff0c\u5f97\u4e0d\u507f\u5931\u3002\n<\/p>\n<p>\n\t\u7b2c\u56db\u6b65\uff0c\u914d\u7f6e gzip_types image\/png; \u5339\u914d MIME \u7c7b\u578b\u8fdb\u884c\u538b\u7f29\uff0ctext\/html \u9ed8\u8ba4\u88ab\u538b\u7f29\u3002\u5c31\u662f\u914d\u7f6e\u54ea\u4e9b\u7c7b\u578b\u7684\u6587\u4ef6\u5c06\u53ef\u80fd\u4f1a\u88ab\u538b\u7f29\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\n# \u5f00\u542fgzip\r\ngzip on;\r\n# \u542f\u7528gzip\u538b\u7f29\u7684\u6700\u5c0f\u6587\u4ef6\uff0c\u5c0f\u4e8e\u8bbe\u7f6e\u503c\u7684\u6587\u4ef6\u5c06\u4e0d\u4f1a\u538b\u7f29\r\ngzip_min_length 1k;\r\n# gzip \u538b\u7f29\u7ea7\u522b\uff0c1-10\uff0c\u6570\u5b57\u8d8a\u5927\u538b\u7f29\u7684\u8d8a\u597d\uff0c\u4e5f\u8d8a\u5360\u7528CPU\u65f6\u95f4\uff0c\u540e\u9762\u4f1a\u6709\u8be6\u7ec6\u8bf4\u660e\r\ngzip_comp_level 2;\r\n# \u8fdb\u884c\u538b\u7f29\u7684\u6587\u4ef6\u7c7b\u578b\u3002javascript\u6709\u591a\u79cd\u5f62\u5f0f\u3002\u5176\u4e2d\u7684\u503c\u53ef\u4ee5\u5728 mime.types \u6587\u4ef6\u4e2d\u627e\u5230\u3002\r\ngzip_types text\/plain application\/javascript application\/x-javascript text\/css application\/xml text\/javascript;<\/pre>\n<p>\n\t\u8fd0\u884c nginx &ndash;t \u68c0\u67e5\u4e00\u4e0b\u8bed\u6cd5\uff0c\u82e5\u8bed\u6cd5\u68c0\u6d4b\u901a\u8fc7\uff0c\u5219\u5f00\u59cb\u8bbf\u95ee url \u68c0\u6d4b gzip \u662f\u5426\u6dfb\u52a0\u6210\u529f\u3002\n<\/p>\n<p>\n\t\u4f60\u53ef\u4ee5\u6574\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6\uff0c\u6bd4\u5982 bootstrap \u7684\u672a\u538b\u7f29 css\u3001js \u6587\u4ef6\u7b49\u3002\u653e\u5230 nginx \u7684\u53ef\u8bbf\u95ee\u76ee\u5f55\u4e2d\uff0c\u7136\u540e\u542f\u52a8 nginx\u3002\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165 http:\/\/localhost:8080\/\uff0cf12 \u67e5\u770b\u63a7\u5236\u53f0\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Nginx gzip \u538b\u7f29\u6d4b\u8bd5\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fzmg3n7flwj20jw0cb41u.jpg\" style=\"width: 716px;height: 443px\" \/>\n<\/p>\n<p>\n\t\u5982\u679c\u54cd\u5e94\u5934\u4e2d\u6709 Content-Encoding: gzip \u90a3\u5c31\u8bf4\u660e\u5f00\u542f\u4e86 gzip \u538b\u7f29\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Nginx \u5bf9\u9759\u6001\u6587\u4ef6\u538b\u7f29\u6548\u679c\u5bf9\u6bd4\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1fzmg6nwp4jj20i907lq4m.jpg\" style=\"width: 657px;height: 273px\" \/>\n<\/p>\n<p>\n\t\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u538b\u7f29\u524d\u540e\uff0c\u54cd\u5e94\u7684\u65f6\u95f4\uff0c\u6587\u4ef6\u5927\u5c0f\u6765\u5bf9\u6bd4\u662f\u5426\u6210\u529f\u5f00\u542f\u4e86 gzip \u538b\u7f29\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3809\">Nginx \u5f00\u542f gzip \u538b\u7f29<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u524d\u9762\u6211\u5df2\u7ecf\u5199\u8fc7\u4e00\u7bc7 gzip \u7684\u6587\u7ae0\u6765\u505a\u94fa\u57ab\u4e86\u300aLinux \u7684 gzip \u538b\u7f29\u300b\u3002\u8fd9\u7bc7\u6587\u7ae0\u6211\u4eec\u5c31\u6765\u770b\u770b Ngi [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118,6],"tags":[1323,706,1152,313,1154],"class_list":["post-3809","post","type-post","status-publish","format-standard","hentry","category-ndisdevelop","category-yyzt","tag-js","tag-linux","tag-nginx","tag-nginx-tfs"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3809"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3809\/revisions"}],"predecessor-version":[{"id":3810,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3809\/revisions\/3810"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}