{"id":1271,"date":"2019-09-13T13:35:06","date_gmt":"2019-09-13T13:35:06","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=1271"},"modified":"2019-11-19T13:36:14","modified_gmt":"2019-11-19T13:36:14","slug":"nginx-etag-gzip","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2019\/09\/nginx-etag-gzip\/","title":{"rendered":"nginx\u6709\u4e9b\u7248\u672c\u540c\u65f6\u5f00\u542fgzip\u548cetag\u4f1a\u51fa\u73b0\u4e00\u4e9b\u95ee\u9898"},"content":{"rendered":"

nginx\u6709\u4e9b\u7248\u672c\u540c\u65f6\u5f00\u542fgzip\u548cetag\u4f1a\u51fa\u73b0\u4e00\u4e9b\u95ee\u9898.md<\/p>\n

\u4e00\u3001Nginx 1.3.3 \u4ee5\u540e\u7684\u9ed8\u8ba4\u6253\u5f00etag<\/h2>\n

nginx\u4ece1.3.3\u5f00\u59cb\u65b0\u52a0\u4e86\u4e00\u4e2aetag\u53c2\u6570\uff0c\u9ed8\u8ba4\u662f\u6253\u5f00\u7684\u3002<\/p>\n

\n
HTTP\/1.1 200 OK\r\nServer: nginx\/1.12.2\r\nDate: Fri, 15 Feb 2019 03:24:45 GMT\r\nContent-Type: text\/html\r\nContent-Length: 4\r\nLast-Modified: Fri, 15 Feb 2019 03:23:16 GMT\r\nConnection: keep-alive\r\nETag: \"5c6630a4-4\"\r\nAccept-Ranges: bytes<\/code><\/pre>\n<\/div>\n

\u4e8c\u3001Apache\u4e2detag\u7684\u751f\u6210\u7b97\u6cd5<\/h2>\n

\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\u6211\u4eec\u63a2\u8ba8\u8fc7Apache\u4e2dEtag\u7684\u5b9e\u73b0\uff0cApache\u9ed8\u8ba4\u4f1a\u6839\u636einode\u3001\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\u3001\u6587\u4ef6\u5927\u5c0f\u6765\u751f\u6210Etag\u503c\u3002\u5982\u4e0b\uff0c<\/p>\n

\n
FileETag INode MTime Size<\/code><\/pre>\n<\/div>\n

\u6240\u4ee5\u5728\u96c6\u7fa4\u670d\u52a1\u5668\u4e2d\uff0c\u5e94\u5f53\u5173\u95edinode\u9009\u9879\uff0c\u4ee5\u514d\u9020\u6210\u7528\u6237\u62ff\u5230etag\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002<\/p>\n

\u4e09\u3001Nginx\u4e2detag\u7684\u751f\u6210\u7b97\u6cd5<\/h2>\n

\u7ecf\u8fc7\u67e5\u770bNginx\u4ee3\u7801src\/http\/ngx_http_core_module.c<\/p>\n

\n
    etag->value.len = ngx_sprintf(etag->value.data, \"\\\"%xT-%xO\\\"\",\r\n                                  r->headers_out.last_modified_time,\r\n                                  r->headers_out.content_length_n)\r\n                      - etag->value.data;\r\n\r\n    r->headers_out.etag = etag;<\/code><\/pre>\n<\/div>\n

Nginx\u4e2d\u7684etag\u662f\u6839\u636e\u6587\u4ef6\u6700\u540e\u4fee\u6539\u65f6\u95f4+\u6587\u4ef6\u5927\u5c0f<\/strong>\u751f\u6210\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u62c5\u5fc3\u96c6\u7fa4\u4e2dinode\u95ee\u9898\u9020\u6210\u7684\u5f71\u54cd\u3002<\/p>\n

\u56db\u3001Nginx\u4e2dgzip\u5bf9etag\u7684\u5f71\u54cd(\u4ecenginx1.3.3\u5230nginx1.7.3)<\/h2>\n

\u4f46\u5728\u67d0\u4e9b\u7248\u672c(\u4ecenginx1.3.3\u5230nginx1.7.3)\u4e2d\uff0c\u5f53\u5f00\u542fgzip\u65f6\uff0c\u4f1a\u5bfc\u81f4etag\u5934\u4e22\u5931\u3002\u5b98\u65b9\u7ed9\u51fa\u7684\u89e3\u91ca\u662f\u538b\u7f29\u4ee5\u540e\u6587\u4ef6\u5927\u5c0f\u65e0\u6cd5\u4fdd\u8bc1\u3002<\/p>\n

\u67e5\u770b\u6e90\u4ee3\u7801.\/src\/http\/modules\/ngx_http_gzip_filter_module.c\uff0c\u53d1\u73b0gzip\u6a21\u5757\u4f7f\u7528\u4e86ngx_http_clear_etag(r)\u51fd\u6570\u79fb\u9664\u4e86etag\u5934\u90e8\u4fe1\u606f\u3002<\/p>\n

\n
 ngx_str_set(&h->key, \"Content-Encoding\");\r\n    ngx_str_set(&h->value, \"gzip\");\r\n    r->headers_out.content_encoding = h;\r\n\r\n    r->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);<\/code><\/pre>\n<\/div>\n

\u4e94\u3001Nginx1.7.3\u4ee5\u540e\u7684\u60c5\u51b5<\/h2>\n

\u81eaNginx1.7.3\u4ee5\u540e\uff0cnginx\u5728\u5904\u7406gzip\u4e2d\u9047\u5230etag\u5934\u90e8\uff0c\u4f1a\u5c06\u5f3aetag\u81ea\u52a8\u8f6c\u6362\u4e3a\u5f31etag\uff08weak ETAG\uff09\uff0c\u5982\u679c\u9047\u5230\u5f31etag\uff0c\u5219\u4e0d\u4f5c\u5904\u7406\u539f\u6837\u8fd4\u56de\u3002<\/p>\n

\u4e3e\u4e2a\u4f8b\u5b50\uff0cNginx\u5bf9\u4e8e\u672c\u5730\u6587\u4ef6\uff0c\u4f1a\u4f7f\u7528\u5f3aetag\uff0c\u5982\u679c\u5f00\u542fgzip\u5c31\u4f1a\u4f7f\u7528\u5f31etag\u3002<\/p>\n

\n
[root@m.ipcpu.com ~]# curl -s http:\/\/10.140.100.22\/t.html -o \/dev\/null  -vvv\r\n<output omitted>\r\n< HTTP\/1.1 200 OK\r\n< Server: nginx\/1.16.1\r\n< Date: Tue, 19 Nov 2019 08:18:18 GMT\r\n< Content-Type: text\/html\r\n< Content-Length: 779\r\n< Last-Modified: Thu, 24 Oct 2019 08:02:39 GMT\r\n< Connection: keep-alive\r\n< Vary: Accept-Encoding\r\n< ETag: \"5db15a9f-30b\"\r\n< Accept-Ranges: bytes\r\n< \r\n{ [data not shown]\r\n##@@\u542f\u7528gzip\u538b\u7f29\r\n[root@m.ipcpu.com ~]# curl -s http:\/\/10.140.100.22\/t.html -o \/dev\/null  -vvv --compressed\r\n<output omitted>\r\n< HTTP\/1.1 200 OK\r\n< Server: nginx\/1.16.1\r\n< Date: Tue, 19 Nov 2019 08:19:31 GMT\r\n< Content-Type: text\/html\r\n< Last-Modified: Thu, 24 Oct 2019 08:02:39 GMT\r\n< Transfer-Encoding: chunked\r\n< Connection: keep-alive\r\n< Vary: Accept-Encoding\r\n< ETag: W\/\"5db15a9f-30b\"\r\n< Content-Encoding: gzip\r\n< \r\n{ [data not shown]<\/code><\/pre>\n<\/div>\n

\u516d\u3001\u5e38\u7528\u6d4f\u89c8\u5668\u7aef\u7f13\u5b58\u603b\u7ed3<\/h2>\n
\n

Expires(HTTP\/1.0)\/Cache-Control(HTTP\/1.1) Header\u662f\u63a7\u5236\u6d4f\u89c8\u5668\u662f\u5426\u76f4\u63a5\u4ece\u6d4f\u89c8\u5668\u7f13\u5b58\u53d6\u6570\u636e\u8fd8\u662f\u91cd\u65b0\u53d1\u8bf7\u6c42\u5230\u670d\u52a1\u5668\u53d6\u6570\u636e\u3002\u53ea\u662fCache-Control\u6bd4Expires\u53ef\u4ee5\u63a7\u5236\u7684\u591a\u4e00\u4e9b\uff0c \u800c\u4e14Cache-Control\u4f1a\u91cd\u5199Expires\u7684\u89c4\u5219\u3002<\/p>\n

Last-Modified\/If-Modified-Since\u548cETag\/If-None-Match\u662f\u6d4f\u89c8\u5668\u53d1\u9001\u8bf7\u6c42\u5230\u670d\u52a1\u5668\u540e\u5224\u65ad\u6587\u4ef6\u662f\u5426 \u5df2\u7ecf\u4fee\u6539\u8fc7\uff0c\u5982\u679c\u6ca1\u6709\u4fee\u6539\u8fc7\u5c31\u53ea\u53d1\u9001\u4e00\u4e2a304\u56de\u7ed9\u6d4f\u89c8\u5668\uff0c\u544a\u8bc9\u6d4f\u89c8\u5668\u76f4\u63a5\u4ece\u81ea\u5df1\u672c\u5730\u7684\u7f13\u5b58\u53d6\u6570\u636e\uff1b\u5982\u679c\u4fee\u6539\u8fc7\u90a3\u5c31\u6574\u4e2a\u6570\u636e\u91cd\u65b0\u53d1\u7ed9\u6d4f\u89c8\u5668\u3002<\/p>\n<\/blockquote>\n

<\/p>\n

\u53c2\u8003\u8d44\u6599<\/h2>\n

https:\/\/github.com\/billfeller\/billfeller.github.io\/issues\/91<\/a>
\n
https:\/\/pureage.info\/2015\/06\/25\/nginx-proxy-cache-and-etag.html<\/a>
\n
https:\/\/www.zhetenga.com\/view\/nginx%E5%BC%80%E5%90%AFgzip%E6%A8%A1%E5%9D%97%E5%90%8EETAG%E4%B8%A2%E5%A4%B1-b666d2155.html<\/a><\/p>\n

<\/p>\n

<\/div>\n
<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n

<\/wiz_tmp_tag><\/p>\n

\u6765\u81ea\u4e3a\u77e5\u7b14\u8bb0(Wiz)<\/a><\/div>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » nginx\u6709\u4e9b\u7248\u672c\u540c\u65f6\u5f00\u542fgzip\u548cetag\u4f1a\u51fa\u73b0\u4e00\u4e9b\u95ee\u9898<\/a><\/p>","protected":false},"excerpt":{"rendered":"

nginx\u6709\u4e9b\u7248\u672c\u540c\u65f6\u5f00\u542fgzip\u548cetag\u4f1a\u51fa\u73b0\u4e00\u4e9b\u95ee\u9898.md \u4e00\u3001Nginx 1.3.3 \u4ee5\u540e\u7684\u9ed8\u8ba4\u6253\u5f00etag nginx\u4ece1.3.3\u5f00\u59cb\u65b0\u52a0\u4e86\u4e00\u4e2aetag\u53c2\u6570\uff0c\u9ed8\u8ba4\u662f\u6253\u5f00\u7684\u3002 HTTP\/1.1 200 OK Server: nginx\/1.12.2 Date: Fri, 15 Feb 2019 03:24:45 GMT Content-Type: text\/html Content-Length: 4 Last-Modified: Fri, 15 Feb 2019 03:23:16 GMT Connection: keep-alive ETag: “5c6630a4-4” Accept-Ranges: bytes \u4e8c\u3001Apache\u4e2detag\u7684\u751f\u6210\u7b97\u6cd5 \u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\u6211\u4eec\u63a2\u8ba8\u8fc7Apache\u4e2dEtag\u7684\u5b9e\u73b0\uff0cApache\u9ed8\u8ba4\u4f1a\u6839\u636einode\u3001\u6587\u4ef6\u4fee\u6539\u65f6\u95f4\u3001\u6587\u4ef6\u5927\u5c0f\u6765\u751f\u6210Etag\u503c\u3002\u5982\u4e0b\uff0c FileETag INode MTime Size \u6240\u4ee5\u5728\u96c6\u7fa4\u670d\u52a1\u5668\u4e2d\uff0c\u5e94\u5f53\u5173\u95edinode\u9009\u9879\uff0c\u4ee5\u514d\u9020\u6210\u7528\u6237\u62ff\u5230etag\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002 \u4e09\u3001Nginx\u4e2detag\u7684\u751f\u6210\u7b97\u6cd5 \u7ecf\u8fc7\u67e5\u770bNginx\u4ee3\u7801src\/http\/ngx_http_core_module.c etag->value.len = ngx_sprintf(etag->value.data, “\\”%xT-%xO\\””, r->headers_out.last_modified_time, r->headers_out.content_length_n) – etag->value.data; r->headers_out.etag = etag; Nginx\u4e2d\u7684etag\u662f\u6839\u636e\u6587\u4ef6\u6700\u540e\u4fee\u6539\u65f6\u95f4+\u6587\u4ef6\u5927\u5c0f\u751f\u6210\u7684\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u62c5\u5fc3\u96c6\u7fa4\u4e2dinode\u95ee\u9898\u9020\u6210\u7684\u5f71\u54cd\u3002 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[202,17,14],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1271"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1271"}],"version-history":[{"count":2,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1271\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1271\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}