{"id":50028,"date":"2024-10-08T09:25:16","date_gmt":"2024-10-08T01:25:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/50028\/"},"modified":"2024-10-08T09:25:16","modified_gmt":"2024-10-08T01:25:16","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%95%9f%e7%94%a8-http-2-%e4%bb%a5%e6%8f%90%e9%ab%98%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/50028\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u555f\u7528 HTTP\/2 \u4ee5\u63d0\u9ad8\u6027\u80fd"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%95%9f%e7%94%a8-http-2-%e4%bb%a5%e6%8f%90%e9%ab%98%e6%80%a7%e8%83%bd-OCJKBVPGHl\">Nginx \u6280\u5de7\uff1a\u555f\u7528 HTTP\/2 \u4ee5\u63d0\u9ad8\u6027\u80fd<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u6027\u80fd\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u7db2\u7d61\u6280\u8853\u7684\u767c\u5c55\uff0cHTTP\/2 \u4f5c\u70ba HTTP \u5354\u8b70\u7684\u6700\u65b0\u7248\u672c\uff0c\u63d0\u4f9b\u4e86\u591a\u9805\u512a\u5316\u529f\u80fd\uff0c\u80fd\u986f\u8457\u63d0\u9ad8\u7db2\u7ad9\u7684\u52a0\u8f09\u901f\u5ea6\u548c\u6027\u80fd\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 Nginx \u4e2d\u555f\u7528 HTTP\/2 \u4ee5\u53ca\u5176\u5e36\u4f86\u7684\u597d\u8655\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-http-2%ef%bc%9f-OCJKBVPGHl\">\u4ec0\u9ebc\u662f HTTP\/2\uff1f<\/h2>\n<p>HTTP\/2 \u662f\u4e00\u7a2e\u57fa\u65bc\u4e8c\u9032\u5236\u7684\u5354\u8b70\uff0c\u76f8\u6bd4\u65bc\u5176\u524d\u8eab HTTP\/1.1\uff0cHTTP\/2 \u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u6548\u7387\u548c\u66f4\u4f4e\u7684\u5ef6\u9072\u3002\u5176\u4e3b\u8981\u7279\u6027\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u591a\u8def\u5fa9\u7528\uff1a<\/strong>\u5141\u8a31\u540c\u6642\u767c\u9001\u591a\u500b\u8acb\u6c42\u548c\u97ff\u61c9\uff0c\u6e1b\u5c11\u4e86\u5ef6\u9072\u3002<\/li>\n<li><strong>\u982d\u90e8\u58d3\u7e2e\uff1a<\/strong>\u4f7f\u7528 HPACK \u7b97\u6cd5\u58d3\u7e2e HTTP \u6a19\u982d\uff0c\u6e1b\u5c11\u4e86\u6578\u64da\u50b3\u8f38\u91cf\u3002<\/li>\n<li><strong>\u670d\u52d9\u5668\u63a8\u9001\uff1a<\/strong>\u670d\u52d9\u5668\u53ef\u4ee5\u4e3b\u52d5\u5411\u5ba2\u6236\u7aef\u63a8\u9001\u8cc7\u6e90\uff0c\u9032\u4e00\u6b65\u63d0\u9ad8\u52a0\u8f09\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87-nginx%ef%bc%9f-OCJKBVPGHl\">\u70ba\u4ec0\u9ebc\u9078\u64c7 Nginx\uff1f<\/h2>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684 HTTP \u4f3a\u670d\u5668\u548c\u53cd\u5411\u4ee3\u7406\u4f3a\u670d\u5668\uff0c\u56e0\u5176\u8f15\u91cf\u7d1a\u548c\u9ad8\u6548\u80fd\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002Nginx \u652f\u6301 HTTP\/2\uff0c\u4e26\u4e14\u914d\u7f6e\u76f8\u5c0d\u7c21\u55ae\uff0c\u9069\u5408\u5404\u7a2e\u898f\u6a21\u7684\u7db2\u7ad9\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-nginx-%e4%b8%ad%e5%95%9f%e7%94%a8-http-2-OCJKBVPGHl\">\u5982\u4f55\u5728 Nginx \u4e2d\u555f\u7528 HTTP\/2<\/h2>\n<p>\u555f\u7528 HTTP\/2 \u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\uff0c\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e7%a2%ba%e4%bf%9d-nginx-%e7%89%88%e6%9c%ac%e6%94%af%e6%8c%81-http-2-OCJKBVPGHl\">1. \u78ba\u4fdd Nginx \u7248\u672c\u652f\u6301 HTTP\/2<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u8a8d\u60a8\u7684 Nginx \u7248\u672c\u662f\u5426\u652f\u6301 HTTP\/2\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u7248\u672c\uff1a<\/p>\n<pre><code>nginx -v<\/code><\/pre>\n<p>HTTP\/2 \u652f\u6301\u5f9e Nginx 1.9.5 \u958b\u59cb\u3002\u5982\u679c\u60a8\u7684\u7248\u672c\u8f03\u820a\uff0c\u8acb\u8003\u616e\u5347\u7d1a\u3002<\/p>\n<h3 id=\"2-%e4%bf%ae%e6%94%b9-nginx-%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-OCJKBVPGHl\">2. \u4fee\u6539 Nginx \u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u627e\u5230 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/nginx.conf \u6216 \/etc\/nginx\/sites-available\/default\u3002\u6253\u958b\u914d\u7f6e\u6587\u4ef6\uff0c\u627e\u5230 server \u5340\u584a\uff0c\u4e26\u6dfb\u52a0 <code>http2<\/code> \u6a19\u8a8c\uff1a<\/p>\n<pre><code>server {\n    listen 443 ssl http2;\n    server_name example.com;\n\n    ssl_certificate \/path\/to\/certificate.crt;\n    ssl_certificate_key \/path\/to\/private.key;\n\n    location \/ {\n        root \/var\/www\/html;\n        index index.html index.htm;\n    }\n}<\/code><\/pre>\n<p>\u5728 <code>listen<\/code> \u6307\u4ee4\u4e2d\u6dfb\u52a0 <code>http2<\/code>\uff0c\u9019\u6a23\u5c31\u555f\u7528\u4e86 HTTP\/2\u3002<\/p>\n<h3 id=\"3-%e9%87%8d%e6%96%b0%e5%95%9f%e5%8b%95-nginx-OCJKBVPGHl\">3. \u91cd\u65b0\u555f\u52d5 Nginx<\/h3>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u60a8\u9700\u8981\u91cd\u65b0\u555f\u52d5 Nginx \u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6-http-2-%e6%98%af%e5%90%a6%e5%95%9f%e7%94%a8-OCJKBVPGHl\">\u6e2c\u8a66 HTTP\/2 \u662f\u5426\u555f\u7528<\/h2>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u591a\u7a2e\u5de5\u5177\u4f86\u6aa2\u67e5\u60a8\u7684\u7db2\u7ad9\u662f\u5426\u6210\u529f\u555f\u7528\u4e86 HTTP\/2\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Chrome \u958b\u767c\u8005\u5de5\u5177\uff0c\u6216\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u5982 <code>curl<\/code>\uff1a<\/p>\n<pre><code>curl -I -s --http2 https:\/\/example.com<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u770b\u5230 <code>HTTP\/2<\/code> \u7684\u97ff\u61c9\uff0c\u5247\u8868\u793a HTTP\/2 \u5df2\u6210\u529f\u555f\u7528\u3002<\/p>\n<h2 id=\"http-2-%e7%9a%84%e5%84%aa%e5%8b%a2-OCJKBVPGHl\">HTTP\/2 \u7684\u512a\u52e2<\/h2>\n<p>\u555f\u7528 HTTP\/2 \u5f8c\uff0c\u60a8\u5c07\u80fd\u5920\u4eab\u53d7\u5230\u4ee5\u4e0b\u512a\u52e2\uff1a<\/p>\n<ul>\n<li><strong>\u66f4\u5feb\u7684\u52a0\u8f09\u6642\u9593\uff1a<\/strong>\u591a\u8def\u5fa9\u7528\u548c\u982d\u90e8\u58d3\u7e2e\u6280\u8853\u80fd\u986f\u8457\u6e1b\u5c11\u9801\u9762\u52a0\u8f09\u6642\u9593\u3002<\/li>\n<li><strong>\u66f4\u597d\u7684\u7528\u6236\u9ad4\u9a57\uff1a<\/strong>\u7528\u6236\u5728\u8a2a\u554f\u7db2\u7ad9\u6642\uff0c\u80fd\u5920\u611f\u53d7\u5230\u66f4\u6d41\u66a2\u7684\u64cd\u4f5c\u9ad4\u9a57\u3002<\/li>\n<li><strong>SEO \u512a\u52e2\uff1a<\/strong>\u7db2\u7ad9\u6027\u80fd\u7684\u63d0\u5347\u6709\u52a9\u65bc\u63d0\u9ad8\u641c\u7d22\u5f15\u64ce\u6392\u540d\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-OCJKBVPGHl\">\u7e3d\u7d50<\/h2>\n<p>\u555f\u7528 HTTP\/2 \u662f\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u4e00\u500b\u6709\u6548\u65b9\u6cd5\uff0c\u7279\u5225\u662f\u5728\u4f7f\u7528 Nginx \u4f5c\u70ba\u4f3a\u670d\u5668\u7684\u60c5\u6cc1\u4e0b\u3002\u901a\u904e\u7c21\u55ae\u7684\u914d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u4eab\u53d7\u5230\u66f4\u5feb\u7684\u52a0\u8f09\u901f\u5ea6\u548c\u66f4\u597d\u7684\u7528\u6236\u9ad4\u9a57\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u90e8\u7f72\u548c\u7ba1\u7406\u60a8\u7684\u7db2\u7ad9\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a> \u9084\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u670d\u52a1\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Nginx \u4e2d\u555f\u7528 HTTP\/2\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\uff0c\u589e\u5f37\u52a0\u8f09\u901f\u5ea6\uff0c\u6539\u5584\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-50028","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=50028"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50028\/revisions"}],"predecessor-version":[{"id":50029,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/50028\/revisions\/50029"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=50028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=50028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=50028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}