{"id":1880,"date":"2023-06-19T17:48:00","date_gmt":"2023-06-19T09:48:00","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=1880"},"modified":"2023-06-19T17:48:00","modified_gmt":"2023-06-19T09:48:00","slug":"%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90-nginx%e5%90%af%e5%8a%a8gzip","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/nginx\/%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90-nginx%e5%90%af%e5%8a%a8gzip\/","title":{"rendered":"\u6027\u80fd\u5206\u6790-Nginx\u542f\u52a8gzip"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<section style=\"margin-bottom: 8px;\">Nginx \u63d0\u4f9b\u4e86 gzip \u538b\u7f29\u529f\u80fd\uff0c\u7528\u4e8e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u5bf9\u54cd\u5e94\u5185\u5bb9\u8fdb\u884c\u538b\u7f29\uff0c\u4ece\u800c\u51cf\u5c11\u4f20\u8f93\u6570\u636e\u7684\u5927\u5c0f\uff0c\u63d0\u9ad8\u7f51\u7ad9\u7684\u52a0\u8f7d\u901f\u5ea6\u548c\u6027\u80fd\u3002gzip \u538b\u7f29\u901a\u5e38\u9002\u7528\u4e8e\u6587\u672c\u7c7b\u578b\u7684\u54cd\u5e94\uff0c\u4f8b\u5982 HTML\u3001CSS\u3001JavaScript \u548c XML \u7b49\u6587\u4ef6\u3002<\/section>\n<section style=\"margin-bottom: 8px;\"><\/section>\n<section style=\"margin-bottom: 8px;\">\u4ee5\u4e0b\u662f\u4e00\u4e9b\u9002\u7528\u573a\u666f\u548c\u6ce8\u610f\u4e8b\u9879\uff0c\u4ee5\u4fbf\u6b63\u786e\u914d\u7f6e\u548c\u4f7f\u7528 Nginx \u7684 gzip \u538b\u7f29\u529f\u80fd\uff1a<\/section>\n<section style=\"margin-bottom: 8px;\">1. \u5e26\u5bbd\u9650\u5236\u7684\u60c5\u51b5\uff1a\u5f53\u4f60\u7684\u670d\u52a1\u5668\u7684\u5e26\u5bbd\u6709\u9650\u65f6\uff0c\u542f\u7528 gzip \u538b\u7f29\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u4f20\u8f93\u6570\u636e\u7684\u5927\u5c0f\uff0c\u4ece\u800c\u8282\u7701\u5e26\u5bbd\u8d44\u6e90\uff0c\u63d0\u9ad8\u7f51\u7ad9\u7684\u54cd\u5e94\u901f\u5ea6\u3002<\/section>\n<section style=\"margin-bottom: 8px;\">2. \u9ad8\u5ef6\u8fdf\u7f51\u7edc\u73af\u5883\uff1a\u5728\u9ad8\u5ef6\u8fdf\u7684\u7f51\u7edc\u73af\u5883\u4e2d\uff0c\u542f\u7528 gzip \u538b\u7f29\u53ef\u4ee5\u51cf\u5c11\u6570\u636e\u4f20\u8f93\u7684\u65f6\u95f4\uff0c\u52a0\u5feb\u9875\u9762\u7684\u52a0\u8f7d\u901f\u5ea6\u3002\u8fd9\u5bf9\u4e8e\u5168\u7403\u5206\u5e03\u7684\u7528\u6237\u3001\u79fb\u52a8\u7f51\u7edc\u8fde\u63a5\u6216\u9ad8\u5ef6\u8fdf\u7f51\u7edc\u90fd\u5f88\u6709\u5e2e\u52a9\u3002<\/section>\n<section style=\"margin-bottom: 8px;\">3. \u5927\u578b\u6587\u4ef6\u7684\u4f20\u8f93\uff1a\u5bf9\u4e8e\u5927\u578b\u7684\u6587\u672c\u6587\u4ef6\uff08\u5982\u957f\u7684 CSS \u6216 JavaScript \u6587\u4ef6\uff09\uff0cgzip \u538b\u7f29\u53ef\u4ee5\u6709\u6548\u51cf\u5c11\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u4ece\u800c\u52a0\u5feb\u6587\u4ef6\u7684\u4f20\u8f93\u901f\u5ea6\u3002<\/section>\n<section style=\"margin-bottom: 8px;\">4. \u914d\u7f6e\u6ce8\u610f\u4e8b\u9879\uff1a<\/section>\n<ul class=\"list-paddingleft-1\" style=\"list-style-type: disc;\">\n<li style=\"list-style-type: none;\">\n<ul class=\"list-paddingleft-1\" style=\"list-style-type: square;\">\n<li style=\"list-style-type: none;\">\n<ul class=\"list-paddingleft-1\" style=\"list-style-type: circle;\">\n<li>\n<section style=\"margin-bottom: 8px;\">\u5728\u542f\u7528 gzip \u538b\u7f29\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4f60\u7684\u670d\u52a1\u5668\u6709\u8db3\u591f\u7684 CPU \u8d44\u6e90\u6765\u5904\u7406\u538b\u7f29\u548c\u89e3\u538b\u7f29\u64cd\u4f5c\u3002<strong>\u542f\u7528 gzip \u538b\u7f29\u4f1a\u589e\u52a0\u670d\u52a1\u5668\u7684 CPU \u8d1f\u8f7d<\/strong>\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-bottom: 8px;\"><span style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.034em;\">\u4ec5\u5bf9\u6587\u672c\u7c7b\u578b\u7684\u54cd\u5e94\u542f\u7528 gzip \u538b\u7f29\uff0c\u907f\u514d\u5bf9\u5df2\u7ecf\u538b\u7f29\u7684\u6587\u4ef6\uff08\u5982\u56fe\u7247\u3001\u97f3\u89c6\u9891\u7b49\uff09\u518d\u6b21\u8fdb\u884c\u538b\u7f29\uff0c\u8fd9\u53ea\u4f1a\u6d6a\u8d39 CPU \u8d44\u6e90\u800c\u4e0d\u4f1a\u5e26\u6765\u5b9e\u9645\u7684\u538b\u7f29\u6548\u679c\u3002<\/span><\/section>\n<\/li>\n<li>\n<section style=\"margin-bottom: 8px;\"><span style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.034em;\">\u542f\u7528 gzip \u538b\u7f29\u7684\u540c\u65f6\uff0c\u786e\u4fdd\u5ba2\u6237\u7aef\u80fd\u591f\u6b63\u786e\u89e3\u538b\u7f29\u54cd\u5e94\u5185\u5bb9\u3002<\/span><span style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.034em;\">\u5927\u591a\u6570\u73b0\u4ee3\u6d4f\u89c8\u5668\u90fd\u652f\u6301 gzip \u538b\u7f29\uff0c\u4f46\u786e\u4fdd\u5728\u5ba2\u6237\u7aef\u548c\u4ee3\u7406\u670d\u52a1\u5668\u4e0a\u8bbe\u7f6e\u6b63\u786e\u7684\u54cd\u5e94\u5934\u4ee5\u786e\u4fdd\u6b63\u786e\u89e3\u538b\u7f29\u3002<\/span><\/section>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<section style=\"margin-bottom: 8px;\"><\/section>\n<section style=\"margin-bottom: 8px;\">\u5728 Nginx \u4e2d\u542f\u7528 gzip \u538b\u7f29\u9700\u8981\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u9002\u5f53\u7684\u8bbe\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u914d\u7f6e\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u542f\u7528 gzip \u538b\u7f29\uff1a<\/section>\n<section><\/section>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"http\"><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__attribute\">http\u00a0{\n<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    gzip on;<\/span><\/code><code><span class=\"code-snippet_outer\">\n    gzip_types text\/html text\/css application\/javascript;<\/span><\/code>\n<code><span class=\"code-snippet_outer\">}<\/span><\/code><\/pre>\n<\/section>\n<section style=\"margin-bottom: 8px;\"><\/section>\n<section style=\"margin-bottom: 8px;\">\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c'gzip on'\u00a0\u8868\u793a\u542f\u7528\u4e86 gzip \u538b\u7f29\uff0c'gzip_types' \u6307\u5b9a\u4e86\u9700\u8981\u8fdb\u884c\u538b\u7f29\u7684\u6587\u4ef6\u7c7b\u578b\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6dfb\u52a0\u6216\u4fee\u6539\u3002<\/section>\n<hr style=\"border-style: solid; border-width: 1px 0 0; border-color: rgba(0,0,0,0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5);\" \/>\n<section style=\"margin-bottom: 8px;\"><\/section>\n<section style=\"margin-bottom: 8px;\">\u5982\u679c\u5927\u5bb6\u5bf9\u6027\u80fd\u6d4b\u8bd5\u89c6\u9891\u6559\u7a0b\u6709\u5174\u8da3\uff0c\u8bf7\u626b\u63cf\u5982\u4e0b\u4e8c\u7ef4\u7801\u67e5\u9605\u3002\u8c22\u8c22\u3002<\/section>\n<p style=\"text-align: center;\">\n<p style=\"display: none;\">\n<blockquote><p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7: \u6d4b\u8bd5DAO<\/p><\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>Nginx \u63d0\u4f9b\u4e86 gzip \u538b\u7f29\u529f\u80fd\uff0c\u7528\u4e8e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u5bf9\u54cd\u5e94\u5185\u5bb9\u8fdb\u884c\u538b\u7f29\uff0c\u4ece\u800c\u51cf\u5c11\u4f20\u8f93\u6570\u636e\u7684\u5927\u5c0f\uff0c\u63d0\u9ad8\u7f51\u7ad9\u7684\u52a0\u8f7d\u901f\u5ea6\u548c\u6027\u80fd\u3002gz &#8230;<\/p>\n","protected":false},"author":1,"featured_media":1878,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-1880","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nginx"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045743375-150x150.jpeg","content_first_image":null,"post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045743375-300x127.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045743375.jpeg","post_frist_image":null,"post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045743375-300x127.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045743375.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528045743375.jpeg","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Nginx","post_date":"2023-06-19","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":289,"next_post_id":1751,"next_post_title":"keepalive + nginx \u5b9e\u73b0\u9ad8\u53ef\u7528","previous_post_id":1009,"previous_post_title":"08-Nginx\u56db\u5c42\u8d1f\u8f7d\u5747\u8861","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1880"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1880\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/1878"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}