{"id":33536,"date":"2024-09-30T22:51:39","date_gmt":"2024-09-30T14:51:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/33536\/"},"modified":"2024-09-30T22:51:39","modified_gmt":"2024-09-30T14:51:39","slug":"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8mod_http2%e9%80%b2%e8%a1%8c%e4%bc%ba%e6%9c%8d%e5%99%a8%e6%8e%a8%e9%80%81%e6%94%af%e6%8c%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/33536\/","title":{"rendered":"Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528mod_http2\u9032\u884c\u4f3a\u670d\u5668\u63a8\u9001\u652f\u6301"},"content":{"rendered":"<h1 id=\"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8mod_http2%e9%80%b2%e8%a1%8c%e4%bc%ba%e6%9c%8d%e5%99%a8%e6%8e%a8%e9%80%81%e6%94%af%e6%8c%81-DlrHJBJflB\">Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528mod_http2\u9032\u884c\u4f3a\u670d\u5668\u63a8\u9001\u652f\u6301<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u662f\u6bcf\u500b\u7db2\u7ad9\u7ba1\u7406\u54e1\u5fc5\u9808\u8003\u616e\u7684\u91cd\u8981\u56e0\u7d20\u3002Apache\u4f5c\u70ba\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u529f\u80fd\u4f86\u589e\u5f37\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002\u5176\u4e2d\uff0c<code>mod_http2<\/code>\u6a21\u7d44\u7684\u5f15\u5165\uff0c\u70baApache\u4f3a\u670d\u5668\u63d0\u4f9b\u4e86HTTP\/2\u7684\u652f\u6301\uff0c\u4e26\u4e14\u5141\u8a31\u4f3a\u670d\u5668\u63a8\u9001\u529f\u80fd\uff0c\u9019\u5c0d\u65bc\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u548c\u7db2\u7ad9\u901f\u5ea6\u5177\u6709\u91cd\u8981\u610f\u7fa9\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afhttp-2%e5%92%8c%e4%bc%ba%e6%9c%8d%e5%99%a8%e6%8e%a8%e9%80%81%ef%bc%9f-DlrHJBJflB\">\u4ec0\u9ebc\u662fHTTP\/2\u548c\u4f3a\u670d\u5668\u63a8\u9001\uff1f<\/h2>\n<p>HTTP\/2\u662fHTTP\u5354\u8b70\u7684\u7b2c\u4e8c\u500b\u4e3b\u8981\u7248\u672c\uff0c\u65e8\u5728\u63d0\u9ad8\u7db2\u9801\u52a0\u8f09\u901f\u5ea6\u548c\u6548\u7387\u3002\u8207HTTP\/1.1\u76f8\u6bd4\uff0cHTTP\/2\u5f15\u5165\u4e86\u591a\u8def\u5fa9\u7528\u3001\u982d\u90e8\u58d3\u7e2e\u548c\u4f3a\u670d\u5668\u63a8\u9001\u7b49\u65b0\u7279\u6027\u3002\u4f3a\u670d\u5668\u63a8\u9001\u5141\u8a31\u4f3a\u670d\u5668\u5728\u5ba2\u6236\u7aef\u8acb\u6c42\u4e4b\u524d\u4e3b\u52d5\u767c\u9001\u8cc7\u6e90\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u8acb\u6c42\u7684\u5ef6\u9072\u6642\u9593\uff0c\u5f9e\u800c\u52a0\u5feb\u9801\u9762\u7684\u52a0\u8f09\u901f\u5ea6\u3002<\/p>\n<h2 id=\"%e5%95%9f%e7%94%a8mod_http2-DlrHJBJflB\">\u555f\u7528mod_http2<\/h2>\n<p>\u8981\u5728Apache\u4e2d\u555f\u7528<code>mod_http2<\/code>\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fddApache\u7248\u672c\u652f\u6301HTTP\/2\u3002\u901a\u5e38\uff0cApache 2.4.17\u53ca\u4ee5\u4e0a\u7248\u672c\u90fd\u652f\u6301\u6b64\u6a21\u7d44\u3002\u4ee5\u4e0b\u662f\u555f\u7528<code>mod_http2<\/code>\u7684\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo a2enmod http2\nsudo systemctl restart apache2\n<\/code><\/pre>\n<p>\u555f\u7528\u5f8c\uff0c\u60a8\u9700\u8981\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u8a2d\u7f6eHTTP\/2\u3002\u53ef\u4ee5\u5728\u865b\u64ec\u4e3b\u6a5f\u914d\u7f6e\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>&lt;VirtualHost *:443&gt;\n    Protocols h2 http\/1.1\n    ...\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae%e4%bc%ba%e6%9c%8d%e5%99%a8%e6%8e%a8%e9%80%81-DlrHJBJflB\">\u914d\u7f6e\u4f3a\u670d\u5668\u63a8\u9001<\/h2>\n<p>\u4e00\u65e6<code>mod_http2<\/code>\u555f\u7528\uff0c\u60a8\u53ef\u4ee5\u958b\u59cb\u914d\u7f6e\u4f3a\u670d\u5668\u63a8\u9001\u3002\u4f3a\u670d\u5668\u63a8\u9001\u7684\u914d\u7f6e\u901a\u5e38\u5728\u865b\u64ec\u4e3b\u6a5f\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u9032\u884c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;Location \/&gt;\n    PushResource \/css\/style.css\n    PushResource \/js\/script.js\n&lt;\/Location&gt;\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u7576\u5ba2\u6236\u7aef\u8acb\u6c42\u4e3b\u9801\u6642\uff0c\u4f3a\u670d\u5668\u6703\u81ea\u52d5\u63a8\u9001CSS\u548cJavaScript\u6587\u4ef6\uff0c\u9019\u6a23\u7528\u6236\u5728\u52a0\u8f09\u4e3b\u9801\u6642\u5c31\u4e0d\u9700\u8981\u7b49\u5f85\u9019\u4e9b\u8cc7\u6e90\u7684\u8acb\u6c42\u3002<\/p>\n<h2 id=\"%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-DlrHJBJflB\">\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5118\u7ba1HTTP\/2\u548c\u4f3a\u670d\u5668\u63a8\u9001\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u6027\u80fd\uff0c\u4f46\u5728\u5be6\u65bd\u9019\u4e9b\u529f\u80fd\u6642\uff0c\u5b89\u5168\u6027\u4ecd\u7136\u662f\u4e0d\u53ef\u5ffd\u8996\u7684\u56e0\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff0c\u4ee5\u78ba\u4fdd\u60a8\u7684Apache\u4f3a\u670d\u5668\u5728\u4f7f\u7528<code>mod_http2<\/code>\u6642\u4fdd\u6301\u5b89\u5168\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528SSL\/TLS\uff1a<\/strong>HTTP\/2\u901a\u5e38\u9700\u8981HTTPS\uff0c\u56e0\u6b64\u78ba\u4fdd\u60a8\u7684\u4f3a\u670d\u5668\u914d\u7f6e\u4e86\u6709\u6548\u7684SSL\u8b49\u66f8\u3002<\/li>\n<li><strong>\u9650\u5236\u63a8\u9001\u8cc7\u6e90\uff1a<\/strong>\u50c5\u63a8\u9001\u5fc5\u8981\u7684\u8cc7\u6e90\uff0c\u4ee5\u6e1b\u5c11\u6f5b\u5728\u7684\u5b89\u5168\u98a8\u96aa\u3002<\/li>\n<li><strong>\u76e3\u63a7\u6d41\u91cf\uff1a<\/strong>\u5b9a\u671f\u6aa2\u67e5\u4f3a\u670d\u5668\u65e5\u8a8c\uff0c\u4ee5\u8b58\u5225\u4efb\u4f55\u7570\u5e38\u6d3b\u52d5\u6216\u6f5b\u5728\u7684\u653b\u64ca\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-DlrHJBJflB\">\u7d50\u8ad6<\/h2>\n<p>\u4f7f\u7528<code>mod_http2<\/code>\u9032\u884c\u4f3a\u670d\u5668\u63a8\u9001\u652f\u6301\uff0c\u80fd\u5920\u986f\u8457\u63d0\u5347\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002\u7136\u800c\uff0c\u5728\u4eab\u53d7\u9019\u4e9b\u512a\u52e2\u7684\u540c\u6642\uff0c\u7db2\u7ad9\u7ba1\u7406\u54e1\u5fc5\u9808\u4fdd\u6301\u5c0d\u5b89\u5168\u6027\u7684\u9ad8\u5ea6\u91cd\u8996\u3002\u901a\u904e\u6b63\u78ba\u7684\u914d\u7f6e\u548c\u5b89\u5168\u63aa\u65bd\uff0c\u60a8\u53ef\u4ee5\u5145\u5206\u5229\u7528Apache\u7684\u5f37\u5927\u529f\u80fd\uff0c\u70ba\u7528\u6236\u63d0\u4f9b\u66f4\u5feb\u3001\u66f4\u5b89\u5168\u7684\u8a2a\u554f\u9ad4\u9a57\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc<code>VPS<\/code>\u3001<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u548c\u5176\u4ed6\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Apache\u5b89\u5168\u7b56\u7565\uff0c\u900f\u904emod_http2\u5be6\u73fe\u4f3a\u670d\u5668\u63a8\u9001\u652f\u6301\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u5b89\u5168\u6027\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-33536","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/33536","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=33536"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/33536\/revisions"}],"predecessor-version":[{"id":33537,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/33536\/revisions\/33537"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=33536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=33536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=33536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}