{"id":3091,"date":"2013-09-10T10:00:33","date_gmt":"2013-09-10T02:00:33","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=3091"},"modified":"2013-09-10T10:00:33","modified_gmt":"2013-09-10T02:00:33","slug":"%e5%9c%a8nginx%e7%9a%84gzip%e6%a8%a1%e5%9d%97%e4%b8%8a%e6%8e%89%e4%ba%86%e4%b8%aa%e5%9d%91","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/3091.html","title":{"rendered":"\u5728nginx\u7684gzip\u6a21\u5757\u4e0a\u6389\u4e86\u4e2a\u5751"},"content":{"rendered":"<p><span style=\"font-size: small;\">\u4eca\u5929\u5728\u505a\u670d\u52a1\u8fc1\u79fb\u670d\u52a1\u5668\uff0c\u5c06\u540e\u53f0\u6574\u4e2a\u8fc1\u79fb\u5230\u4e91\u670d\u52a1\u5668\u4e0a\uff0c\u524d\u671f\u5f88\u987a\u5229\uff0c\u5ba2\u6237\u7aef\u90fd\u80fd\u6b63\u5e38\u8dd1\u8d77\u6765\uff0c\u63a5\u53e3\u548c\u540e\u53f0\u7ba1\u7406\uff0c\u63a8\u9001\uff0c\u5f02\u6b65\u961f\u5217\u7b49\u90fd\u6b63\u5e38\u8fd0\u884c\u3002\u4f46\u662f\u53d1\u73b0\u4e00\u4e2a\u975e\u5e38\u5947\u602a\u7684\u95ee\u9898\uff0c\u641e\u4e86\u4e00\u4e0b\u5348\u6ca1\u89e3\u51b3\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">ios\u5ba2\u6237\u7aef\u5728\u62c9\u53d6\u63a5\u53e3\u540e\uff0c\u7b2c\u4e00\u6b21\u6210\u529f\uff0c\u7b2c\u4e8c\u6b21\u518d\u5237\u65b0\uff0c\u5c31\u6ca1\u6709\u4efb\u4f55\u7f51\u7edc\u8bf7\u6c42\uff0c\u5f88\u5947\u602a\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u5176\u5b83\u63a5\u53e3\u4e5f\u662f\uff0c\u6210\u529f\u540e\u518d\u5237\u65b0\u6570\u636e\u5c31\u4e0d\u4f1a\u53d8\uff0c\u53d6\u7f13\u5b58\u7684\u6570\u636e\u3002\u56e0\u4e3a\u6293\u5305\u53d1\u73b0\u6ca1\u7f51\u7edc\u8bf7\u6c42\uff0c\u6240\u4ee5\u5728\u540e\u53f0\u628a\u6570\u636e\u6539\u4e86\u540e\uff0c\u5237\u65b0\u5ba2\u6237\u7aef\u770b\u4e0d\u5230\u65b0\u7684\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u4e00\u65e6\u5207\u56de\u5230\u7ebf\u4e0a\uff0c\u8fd9\u79cd\u73b0\u8c61\u5c31\u597d\u4e86\u3002andorid\u5ba2\u6237\u7aef\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u521a\u5f00\u59cb\u4ee5\u4e3a\u662f\u57df\u540d\u7684\u95ee\u9898\uff0c\u4e8e\u662f\u4fdd\u7559\u539f\u57df\u540d\uff0c\u628a\u539f\u57df\u540d\u7684ip\u901a\u8fc7\u4fee\u6539host\u6307\u5411\u65b0\u670d\u52a1\u5668\uff0c\u7528fiddler\u6293\u5305\uff0c\u53d1\u73b0\u95ee\u9898\u8fd8\u662f\u6709\uff0c\u8bf4\u660e\u8ddf\u57df\u540d\u65e0\u5173\uff0c\u662f\u65b0\u670d\u52a1\u6709\u95ee\u9898\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u901a\u8fc7\u5355\u6b65\u8c03\u8bd5ios\u7a0b\u5e8f\uff0c\u4e5f\u6ca1\u53d1\u73b0\u4ec0\u4e48\u5f02\u5e38\uff0c\u7f51\u7edc\u8bf7\u6c42\u7684\u8c03\u8bd5\u4ee3\u7801\u4e5f\u90fd\u6267\u884c\u4e86\u7684\uff0c\u4f46\u5c31\u662f\u6ca1\u6709\u7f51\u7edc\u8bf7\u6c42\uff0c\u53ef\u80fd\u662fios\u5e95\u5c42\u5e93\u76f8\u5173\u95ee\u9898\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u603b\u800c\u8a00\u4e4b\uff0c\u641e\u4e86\u5f88\u4e45\uff0c\u5230\u665a\u4e0a\u4e5d\u70b9\u591a\uff0c\u6700\u7ec8\u53d1\u73b0\uff0c\u5ba2\u6237\u7aef\u8bf7\u6c42\u6ca1\u6709\u5e26Etag\u503c\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u56e0\u4e3a\u6211\u4eec\u7528tornado\u505a\u670d\u52a1\u5668\uff0c\u6bcf\u4e2ahttp\u63a5\u53e3\u8fd4\u56de\u90fd\u4f1a\u6709\u4e00\u4e2aEtag\u503c\u5728header\u91cc\u9762\uff0c\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u65f6\u5019\u5e26\u4e0aEtag\uff0c\u4ece\u800c\u5b9e\u73b0\u6570\u636e\u7f13\u5b58\uff0c\u51cf\u5c11\u4f20\u8f93\u3002\u4f46\u662f\u5947\u602a\uff0c\u5ba2\u6237\u7aef\u8bf7\u6c42\u65b0\u670d\u52a1\u7684\u65f6\u5019\uff0c\u4e00\u5f8b\u6ca1\u6709\u5e26Etag\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u6700\u7ec8\u53d1\u73b0\uff0c\u5176\u5b9e\u662f\u6211\u4eec\u670d\u52a1\u5668\u8fd4\u56de\u5c31\u6839\u672c\u6ca1\u6709Etag\u3002\u56e0\u4e3a\u6211\u4eec\u65b0\u670d\u52a1\u7528\u7684nginx\u7248\u672c\uff0c\u662f\u6839\u636e\u6700\u65b0\u7684nginx\u6e90\u4ee3\u7801\u4fee\u6539image_filter\u63d2\u4ef6\u7684\u4ee3\u7801\u540e\uff0c\u91cd\u65b0\u7f16\u8bd1\u7684\uff0c\u8ddf\u4ee5\u524d\u6211\u4eec\u7528\u7684\u4e0d\u4e00\u6837\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u80fd\u8fc7\u6293\u5305\u5206\u6790\u63a5\u53e3\u8fd4\u56de\u7684header\uff0c\u53d1\u73b0\u7f13\u5b58\u63a7\u5236\u591a\u4e86 Catch-Control: max-age \u8fd9\u4e2a\u5934\uff0c\u53ef\u4ee5\u4fee\u6539nginx\u914d\u7f6e\u53bb\u6389\u3002\u4f46\u4e0d\u662f\u8fd9\u4e2a\u539f\u56e0\u5bfc\u81f4\u6ca1\u6709Etag\u503c\uff0c\u6700\u7ec8\u539f\u56e0\u662fGzip\uff01<\/span><\/p>\n<p><span style=\"font-size: small;\">\u5f53\u53bb\u6389Gzip\u540e\uff0c\u8fd4\u56de\u5c31\u6709Etag\u503c\u4e86\uff0c\u4e8e\u662f\u5c31\u6000\u7591\u662fnginx\u5728\u505agzip\u7684\u65f6\u5019\uff0c\u5c06tornado\u8fd4\u56de\u7684Etag\u5934\u7ed9\u5e72\u6389\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u540e\u6765\u67e5\u8d44\u6599\u53d1\u73b0\uff0c\u65b0\u7248\u7684nginx\u786e\u5b9e\u6709\u8fd9\u4e00\u884c\u4e3a\uff0c\u5728nginx\u6e90\u7801\u4e2d\uff0csrc\/http\/modules\/ngx_http_gzip_filter_module.c \u7b2c306\u884c\u5de6\u53f3\uff0c\u51fd\u6570\uff1a<\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstatic ngx_int_t\r\nngx_http_gzip_header_filter(ngx_http_request_t *r)\r\n\r\n....................\r\n\r\n    r-&gt;main_filter_need_in_memory = 1;\r\n\r\n    ngx_http_clear_content_length(r);\r\n    ngx_http_clear_accept_ranges(r);\r\n    ngx_http_clear_etag(r);                             \/\/\u5c31\u662f\u8fd9\u4e00\u884c\uff0c\u628a\u8fd4\u56de\u7684etag\u5934\u4fe1\u606f\u5e72\u6389\u4e86\r\n\r\n    return ngx_http_next_header_filter(r);\r\n}\r\n<\/pre>\n<p><span style=\"font-size: small;\">\u95ee\u9898\u627e\u5230\u4e86\uff0c\u89e3\u51b3\u529e\u6cd5\u5c31\u5f88\u7b80\u5355\u4e86\uff0c\u628a\u90a3\u884c\u4ee3\u7801\u6ce8\u91ca\u6389\uff0c\u518d\u91cd\u65b0\u7f16\u8bd1\u4e2anginx\u4f7f\u7528\u5c31\u597d\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: small;\">\u5c31\u7b97\u662f\u4e2a\u7591\u96be\u6742\u75c7\uff0c\u641e\u4e86\u597d\u4e45\u624d\u67e5\u5230\u539f\u56e0\uff0c\u4e3b\u8981\u662f\u521a\u5f00\u59cb\u65b9\u5411\u4e0d\u5bf9\uff0c\u6ca1\u4eba\u4f1a\u60f3\u5230\u662fnginx\u5e95\u5c42\u51fa\u7684\u95ee\u9898\uff0c\u8d70\u4e86\u4e0d\u5c11\u5f2f\u8def\u3002\u540c\u65f6\u51fa\u5410\u69fd\u4e00\u4e0bios\u5e95\u5c42\u7f51\u7edc\u5e93\uff0c\u7f3a\u5c11\u4e86etag\u5c31\u4e0d\u7ed9\u7f51\u7edc\u8bf7\u6c42\u4e86\uff0c\u4e5f\u4e0d\u7ed9\u4efb\u4f55\u8b66\u544a\u63d0\u793a\u4e4b\u7c7b\u7684\uff0c\u771f\u662f\u7684\uff01android\u65e0\u95ee\u9898\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u5728\u505a\u670d\u52a1\u8fc1\u79fb\u670d\u52a1\u5668\uff0c\u5c06\u540e\u53f0\u6574\u4e2a\u8fc1\u79fb\u5230\u4e91\u670d\u52a1\u5668\u4e0a\uff0c\u524d\u671f\u5f88\u987a\u5229\uff0c\u5ba2\u6237\u7aef\u90fd\u80fd\u6b63\u5e38\u8dd1\u8d77\u6765\uff0c\u63a5\u53e3\u548c\u540e\u53f0\u7ba1\u7406\uff0c\u63a8\u9001\uff0c\u5f02 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3091","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/3091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=3091"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/3091\/revisions"}],"predecessor-version":[{"id":3092,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/3091\/revisions\/3092"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=3091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=3091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=3091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}