{"id":924,"date":"2017-11-12T18:18:44","date_gmt":"2017-11-12T18:18:44","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=924"},"modified":"2022-09-14T04:50:50","modified_gmt":"2022-09-14T04:50:50","slug":"http2-nginx","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2017\/11\/http2-nginx\/","title":{"rendered":"HTTP2\u7b80\u4ecb\u548cnginx\u4e2d\u5f00\u542fHTTP2"},"content":{"rendered":"

HTTP2\u7b80\u4ecb\u548cnginx\u4e2d\u5f00\u542fHTTP2.md<\/p>\n

<\/p>\n

\u4e00\u3001HTTP\/2\u7b80\u4ecb<\/h2>\n

HTTP\/2\uff08\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae\u7b2c2\u7248\uff0c\u6700\u521d\u547d\u540d\u4e3a HTTP 2.0\uff09\uff0c\u662fHTTP\u534f\u8bae\u7684\u7684\u7b2c\u4e8c\u4e2a\u4e3b\u8981\u7248\u672c\uff0c\u4f7f\u7528\u4e8e\u4e07\u7ef4\u7f51\u3002HTTP\/2 \u662f HTTP \u534f\u8bae\u81ea 1999 \u5e74 HTTP 1.1 \u53d1\u5e03\u540e\u7684\u9996\u4e2a\u66f4\u65b0\uff0c\u4e3b\u8981\u57fa\u4e8e SPDY \u534f\u8bae\u3002\u5b83\u7531\u4e92\u8054\u7f51\u5de5\u7a0b\u4efb\u52a1\u7ec4 (IETF) \u7684 Hypertext Transfer Protocol Bis (httpbis) \u5de5\u4f5c\u5c0f\u7ec4\u8fdb\u884c\u5f00\u53d1\u3002\u8be5\u7ec4\u7ec7\u4e8e2014\u5e7412\u6708\u5c06 HTTP\/2 \u6807\u51c6\u63d0\u8bae\u9012\u4ea4\u81f3IESG\u8fdb\u884c\u8ba8\u8bba\uff0c\u4e8e2015\u5e742\u670817\u65e5\u88ab\u6279\u51c6\u3002HTTP\/2 \u6807\u51c6\u4e8e2015\u5e745\u6708\u4ee5 RFC 7540 \u6b63\u5f0f\u53d1\u8868\u3002<\/p>\n

\u4e8c\u3001HTTP\/2\u4f18\u70b9<\/h2>\n

\u91c7\u7528\u4e8c\u8fdb\u5236\u683c\u5f0f\u4f20\u8f93\u6570\u636e\uff0c\u800c\u975e\u6587\u672c\u683c\u5f0f\u3002\u4e8c\u8fdb\u5236\u683c\u5f0f\u5728\u534f\u8bae\u7684\u89e3\u6790\u548c\u4f18\u5316\u6269\u5c55\u4e0a\u5e26\u6765\u66f4\u591a\u7684\u4f18\u52bf\u548c\u53ef\u80fd\u3002<\/p>\n

\u5bf9\u6d88\u606f\u5934\u8fdb\u884c\u538b\u7f29\u4f20\u8f93\uff0c\u80fd\u591f\u8282\u7701\u6d88\u606f\u5934\u5360\u7528\u7684\u7f51\u7edc\u7684\u6d41\u91cf\uff0c\u800c HTTP 1.1 \u6bcf\u6b21\u8bf7\u6c42\uff0c\u90fd\u4f1a\u643a\u5e26\u5927\u91cf\u5197\u4f59\u5934\u4fe1\u606f\uff0c\u6d6a\u8d39\u4e86\u5f88\u591a\u5e26\u5bbd\u8d44\u6e90\uff0c\u5934\u538b\u7f29\u80fd\u591f\u5f88\u597d\u7684\u89e3\u51b3\u8be5\u95ee\u9898\u3002<\/p>\n

\u591a\u8def\u590d\u7528\uff0c\u5c31\u662f\u591a\u4e2a\u8bf7\u6c42\u90fd\u662f\u901a\u8fc7\u4e00\u4e2a TCP \u8fde\u63a5\u5e76\u53d1\u5b8c\u6210\uff0c HTTP 1.1 \u867d\u7136\u901a\u8fc7 pipeline \u4e5f\u80fd\u5e76\u53d1\u8bf7\u6c42\uff0c\u4f46\u662f\u591a\u4e2a\u8bf7\u6c42\u4e4b\u95f4\u7684\u54cd\u5e94\u4f1a\u88ab\u963b\u585e\u7684\uff0c\u6240\u4ee5 pipeline \u81f3\u4eca\u4e5f\u6ca1\u6709\u88ab\u666e\u53ca\u5e94\u7528\uff0c\u800c HTTP\/2 \u505a\u5230\u4e86\u771f\u6b63\u7684\u5e76\u53d1\u8bf7\u6c42\uff0c\u540c\u65f6\u6d41\u8fd8\u652f\u6301\u4f18\u5148\u7ea7\u548c\u6d41\u91cf\u63a7\u5236\u3002<\/p>\n

\u670d\u52a1\u5668\u63a8\u9001\uff0c\u670d\u52a1\u7aef\u80fd\u591f\u66f4\u5feb\u7684\u628a\u8d44\u6e90\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\uff0c\u4f8b\u5982\u670d\u52a1\u7aef\u53ef\u4ee5\u4e3b\u52a8\u628a JS \u548c CSS \u6587\u4ef6\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\uff0c\u800c\u4e0d\u9700\u8981\u5ba2\u6237\u7aef\u89e3\u6790 HTML \u518d\u53d1\u9001\u8fd9\u4e9b\u8bf7\u6c42\uff0c\u5f53\u5ba2\u6237\u7aef\u9700\u8981\u7684\u65f6\u5019\uff0c\u5b83\u5df2\u7ecf\u5728\u5ba2\u6237\u7aef\u4e86\u3002<\/p>\n

\u4e09\u3001HTTP\/2\u7ad9\u70b9\u7684\u4f18\u52bf<\/h2>\n

\u63d0\u5347\u7f51\u7ad9\u8bbf\u95ee\u901f\u5ea6\u3002
\n\u964d\u4f4e\u670d\u52a1\u5668\u538b\u529b\u3002
\n\u90e8\u5206\u66ff\u4ee3\u5f02\u6b65\u52a0\u8f7d\u7684\u4f7f\u7528\u3002
\n\u4fdd\u62a4\u7f51\u7ad9\u5b89\u5168\u3002<\/p>\n

\u56db\u3001\u4e3a\u4ec0\u4e48\u4e0d\u662fHTTP\/1.2<\/h2>\n

\u4e3a\u4e86\u5b9e\u73b0 HTTP \u5de5\u4f5c\u7ec4\u8bbe\u5b9a\u7684\u6027\u80fd\u76ee\u6807\uff0cHTTP\/2 \u5f15\u5165\u4e86\u4e00\u4e2a\u65b0\u7684\u4e8c\u8fdb\u5236\u5206\u5e27\u5c42\uff0c\u8be5\u5c42\u65e0\u6cd5\u4e0e\u4e4b\u524d\u7684 HTTP\/1.x \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5411\u540e\u517c\u5bb9\uff0c\u56e0\u6b64\u534f\u8bae\u7684\u4e3b\u7248\u672c\u63d0\u5347\u5230 HTTP\/2\u3002<\/p>\n

\u4e94\u3001\u5728Nginx\u4e0a\u542f\u7528HTTP\/2<\/h2>\n

\u5728 Nginx \u4e0a \u5f00\u542f HTTP\/2 \u9700\u8981 Nginx 1.9.5 \u4ee5\u4e0a\u7248\u672c\uff0c\u5e76\u4e14\u9700\u8981 OpenSSL \u7248\u672c\u5728 1.0.2 \u4ee5\u4e0a\u3002<\/p>\n

\u56e0\u4e3a HTTP\/2 \u4e0d\u4ec5\u9700\u8981Web\u670d\u52a1\u5668\u8fd8\u9700\u8981\u4e00\u4e2a\u6269\u5c55\u652f\u6301\uff0c\u76ee\u524d\u53ef\u4ee5\u7528\u7684\u6709 ALPN \u548c NPN \u4e24\u79cd(Chrome \u5df2\u7ecf\u79fb\u9664\u4e86\u5bf9 NPN \u7684\u652f\u6301)\u3002\u53ea\u6709 OpenSSL 1.0.2 \u4ee5\u4e0a\u7248\u672c\u624d\u5f00\u59cb\u652f\u6301 ALPN \u3002<\/p>\n

\u4eceNginx 1.9.5 \u5f00\u59cb\uff0chttp_v2_module \u5df2\u7ecf\u66ff\u6362\u4e86ngx_http_spdy_module\uff0c\u5168\u9762\u652f\u6301HTTP\/2\u534f\u8bae\u3002\u9ed8\u8ba4\u6ca1\u6709\u653e\u8fdb\u7f16\u8bd1\u53c2\u6570\uff0c\u9700\u8981\u7f16\u8bd1\u53c2\u6570--with-http_v2_module\u5f00\u542f\u3002<\/p>\n

\u53ef\u4ee5\u7528nginx -V\u67e5\u770b\u3002<\/p>\n

\n
[root@nginx ~]# nginx -V\nnginx version: nginx\/1.12.2\nbuilt by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)\nbuilt with OpenSSL 1.0.2k-fips  26 Jan 2017\nTLS SNI support enabled\nconfigure arguments: --prefix=\/usr\/share\/nginx --sbin-path=\/usr\/sbin\/nginx  <\u2026\u7701\u7565\u2026> --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module  <\u2026\u7701\u7565\u2026><\/code><\/pre>\n<\/div>\n

\u786e\u4fdd\u652f\u6301http2\u540e\uff0cnginx\u914d\u7f6e\u4f5c\u5982\u4e0b\u4fee\u6539\uff0c<\/p>\n

\n
server {\nlisten 443 ssl http2 ;\nserver_name www.ipcpu.com;<\/code><\/pre>\n<\/div>\n

\u516d\u3001HTTP2\u68c0\u6d4b<\/h2>\n

Chrome\u6709\u4e2a\u63d2\u4ef6 HTTP\/2 and SPDY indicator ,\u5982\u679c\u5730\u5740\u680f\u51fa\u73b0\u84dd\u8272\u7684\u95ea\u7535\u5c31\u662f h2
\n\u4e5f\u53ef\u4ee5\u5728 chrome:\/\/net-internals\/#http2 \u4e2d\u68c0\u67e5<\/p>\n

\u5982\u4e0b\u56fe
\n<\/p>\n

\u4e03\u3001\u6d4f\u89c8\u5668\u652f\u6301<\/h2>\n

\u5f00\u542f\u4e86 HTTP\/2 \u4ee5\u540e\uff0c\u4f4e\u7248\u672c\u6d4f\u89c8\u5668\u4e5f\u662f\u53ef\u6b63\u5e38\u8bbf\u95ee\u7684\u3002\u5982\u679c\u5ba2\u6237\u7aef\u4e0d\u652f\u6301 HTTP\/2 Nginx \u4f1a\u81ea\u52a8\u5411\u4e0b\u517c\u5bb9 HTTP 1.1\u3002<\/p>\n

\u76ee\u524d\u652f\u6301 HTTP\/2 \u6d4f\u89c8\u5668\u5217\u8868<\/p>\n

<\/p>\n

\u516b\u3001HTTP\/2\u7684\u79fb\u52a8\u7aef\u73b0\u72b6<\/h2>\n

\u82f9\u679c\u4eceiOS9\u5f00\u59cb\u652f\u6301HTTP\/2\uff0c\u5bf9iOS\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\uff0c\u5373\u662fiOS9\u5f00\u59cb\uff0cNSURLSession\u53ef\u4ee5\u652f\u6301HTTP\/2\u3002<\/p>\n

\u82f9\u679c\u5df2\u7ecf\u6253\u7b97\u5e9f\u5f03NSURLConnection\uff0c\u6240\u4ee5NSURLConnection\u4e0d\u80fd\u652f\u6301HTTP\/2\u3002<\/p>\n

android\u539f\u751fHttpURLConnection\u5e76\u4e0d\u652f\u6301HTTP\/2\uff0c\u53ef\u4ee5\u9009\u7528\u4e09\u65b9\u5f00\u6e90\u5e93okhttp\u4f5c\u4e3a\u7f51\u7edc\u6846\u67b6<\/p>\n

android 5.0+\u8bbe\u5907\u624d\u652f\u6301HTTP\/2<\/p>\n

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

http:\/\/caniuse.com\/#feat=http2<\/a>
\n
https:\/\/www.hi-linux.com\/posts\/24162.html<\/a>
\n
https:\/\/segmentfault.com\/a\/1190000004399183<\/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

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » HTTP2\u7b80\u4ecb\u548cnginx\u4e2d\u5f00\u542fHTTP2<\/a><\/p>","protected":false},"excerpt":{"rendered":"

HTTP2\u7b80\u4ecb\u548cnginx\u4e2d\u5f00\u542fHTTP2.md \u4e00\u3001HTTP\/2\u7b80\u4ecb HTTP\/2\uff08\u8d85\u6587\u672c\u4f20\u8f93\u534f\u8bae\u7b2c2\u7248\uff0c\u6700\u521d\u547d\u540d\u4e3a HTTP 2.0\uff09\uff0c\u662fHTTP\u534f\u8bae\u7684\u7684\u7b2c\u4e8c\u4e2a\u4e3b\u8981\u7248\u672c\uff0c\u4f7f\u7528\u4e8e\u4e07\u7ef4\u7f51\u3002HTTP\/2 \u662f HTTP \u534f\u8bae\u81ea 1999 \u5e74 HTTP 1.1 \u53d1\u5e03\u540e\u7684\u9996\u4e2a\u66f4\u65b0\uff0c\u4e3b\u8981\u57fa\u4e8e SPDY \u534f\u8bae\u3002\u5b83\u7531\u4e92\u8054\u7f51\u5de5\u7a0b\u4efb\u52a1\u7ec4 (IETF) \u7684 Hypertext Transfer Protocol Bis (httpbis) \u5de5\u4f5c\u5c0f\u7ec4\u8fdb\u884c\u5f00\u53d1\u3002\u8be5\u7ec4\u7ec7\u4e8e2014\u5e7412\u6708\u5c06 HTTP\/2 \u6807\u51c6\u63d0\u8bae\u9012\u4ea4\u81f3IESG\u8fdb\u884c\u8ba8\u8bba\uff0c\u4e8e2015\u5e742\u670817\u65e5\u88ab\u6279\u51c6\u3002HTTP\/2 \u6807\u51c6\u4e8e2015\u5e745\u6708\u4ee5 RFC 7540 \u6b63\u5f0f\u53d1\u8868\u3002 \u4e8c\u3001HTTP\/2\u4f18\u70b9 \u91c7\u7528\u4e8c\u8fdb\u5236\u683c\u5f0f\u4f20\u8f93\u6570\u636e\uff0c\u800c\u975e\u6587\u672c\u683c\u5f0f\u3002\u4e8c\u8fdb\u5236\u683c\u5f0f\u5728\u534f\u8bae\u7684\u89e3\u6790\u548c\u4f18\u5316\u6269\u5c55\u4e0a\u5e26\u6765\u66f4\u591a\u7684\u4f18\u52bf\u548c\u53ef\u80fd\u3002 \u5bf9\u6d88\u606f\u5934\u8fdb\u884c\u538b\u7f29\u4f20\u8f93\uff0c\u80fd\u591f\u8282\u7701\u6d88\u606f\u5934\u5360\u7528\u7684\u7f51\u7edc\u7684\u6d41\u91cf\uff0c\u800c HTTP 1.1 \u6bcf\u6b21\u8bf7\u6c42\uff0c\u90fd\u4f1a\u643a\u5e26\u5927\u91cf\u5197\u4f59\u5934\u4fe1\u606f\uff0c\u6d6a\u8d39\u4e86\u5f88\u591a\u5e26\u5bbd\u8d44\u6e90\uff0c\u5934\u538b\u7f29\u80fd\u591f\u5f88\u597d\u7684\u89e3\u51b3\u8be5\u95ee\u9898\u3002 \u591a\u8def\u590d\u7528\uff0c\u5c31\u662f\u591a\u4e2a\u8bf7\u6c42\u90fd\u662f\u901a\u8fc7\u4e00\u4e2a TCP \u8fde\u63a5\u5e76\u53d1\u5b8c\u6210\uff0c HTTP 1.1 \u867d\u7136\u901a\u8fc7 pipeline \u4e5f\u80fd\u5e76\u53d1\u8bf7\u6c42\uff0c\u4f46\u662f\u591a\u4e2a\u8bf7\u6c42\u4e4b\u95f4\u7684\u54cd\u5e94\u4f1a\u88ab\u963b\u585e\u7684\uff0c\u6240\u4ee5 pipeline \u81f3\u4eca\u4e5f\u6ca1\u6709\u88ab\u666e\u53ca\u5e94\u7528\uff0c\u800c HTTP\/2 \u505a\u5230\u4e86\u771f\u6b63\u7684\u5e76\u53d1\u8bf7\u6c42\uff0c\u540c\u65f6\u6d41\u8fd8\u652f\u6301\u4f18\u5148\u7ea7\u548c\u6d41\u91cf\u63a7\u5236\u3002 \u670d\u52a1\u5668\u63a8\u9001\uff0c\u670d\u52a1\u7aef\u80fd\u591f\u66f4\u5feb\u7684\u628a\u8d44\u6e90\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\uff0c\u4f8b\u5982\u670d\u52a1\u7aef\u53ef\u4ee5\u4e3b\u52a8\u628a JS \u548c CSS \u6587\u4ef6\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\uff0c\u800c\u4e0d\u9700\u8981\u5ba2\u6237\u7aef\u89e3\u6790 HTML \u518d\u53d1\u9001\u8fd9\u4e9b\u8bf7\u6c42\uff0c\u5f53\u5ba2\u6237\u7aef\u9700\u8981\u7684\u65f6\u5019\uff0c\u5b83\u5df2\u7ecf\u5728\u5ba2\u6237\u7aef\u4e86\u3002 \u4e09\u3001HTTP\/2\u7ad9\u70b9\u7684\u4f18\u52bf […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,13],"tags":[137,138,14],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/924"}],"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=924"}],"version-history":[{"count":1,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/924\/revisions"}],"predecessor-version":[{"id":1929,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/924\/revisions\/1929"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}