{"id":40459,"date":"2024-10-01T13:22:52","date_gmt":"2024-10-01T05:22:52","guid":{"rendered":"https:\/\/server.hk\/cnblog\/40459\/"},"modified":"2024-10-01T13:22:52","modified_gmt":"2024-10-01T05:22:52","slug":"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e8%a8%ad%e7%bd%aeapache%e8%88%87mod_proxy_http2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/40459\/","title":{"rendered":"Apache\u65b0\u624b\u6559\u7a0b\uff1a\u8a2d\u7f6eApache\u8207mod_proxy_http2"},"content":{"rendered":"<h1 id=\"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e8%a8%ad%e7%bd%aeapache%e8%88%87mod_proxy_http2-kbSMIdlhea\">Apache\u65b0\u624b\u6559\u7a0b\uff1a\u8a2d\u7f6eApache\u8207mod_proxy_http2<\/h1>\n<p>Apache HTTP Server\uff08\u7c21\u7a31Apache\uff09\u662f\u4e00\u500b\u958b\u6e90\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5f0f\u7684\u6258\u7ba1\u3002\u96a8\u8457\u7db2\u969b\u7db2\u8def\u6280\u8853\u7684\u767c\u5c55\uff0cHTTP\/2\u5354\u8b70\u9010\u6f38\u6210\u70ba\u4e3b\u6d41\uff0c\u56e0\u5176\u63d0\u4f9b\u4e86\u66f4\u5feb\u7684\u52a0\u8f09\u901f\u5ea6\u548c\u66f4\u9ad8\u7684\u6548\u7387\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728Apache\u4e2d\u8a2d\u7f6emod_proxy_http2\u6a21\u7d44\uff0c\u4ee5\u4fbf\u652f\u6301HTTP\/2\u7684\u53cd\u5411\u4ee3\u7406\u529f\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmod_proxy_http2%ef%bc%9f-kbSMIdlhea\">\u4ec0\u9ebc\u662fmod_proxy_http2\uff1f<\/h2>\n<p>mod_proxy_http2\u662fApache\u7684\u4e00\u500b\u6a21\u7d44\uff0c\u5141\u8a31Apache\u4f5c\u70baHTTP\/2\u7684\u53cd\u5411\u4ee3\u7406\u3002\u9019\u610f\u5473\u8457Apache\u53ef\u4ee5\u63a5\u6536HTTP\/2\u8acb\u6c42\u4e26\u5c07\u5176\u8f49\u767c\u5230\u5f8c\u7aef\u4f3a\u670d\u5668\uff0c\u5f9e\u800c\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u97ff\u61c9\u901f\u5ea6\u3002\u4f7f\u7528HTTP\/2\u7684\u4e3b\u8981\u512a\u52e2\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u591a\u8def\u5fa9\u7528\uff1a\u53ef\u4ee5\u5728\u540c\u4e00\u9023\u63a5\u4e0a\u540c\u6642\u8655\u7406\u591a\u500b\u8acb\u6c42\uff0c\u6e1b\u5c11\u5ef6\u9072\u3002<\/li>\n<li>\u982d\u90e8\u58d3\u7e2e\uff1a\u6e1b\u5c11\u50b3\u8f38\u7684\u6578\u64da\u91cf\uff0c\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<li>\u670d\u52d9\u5668\u63a8\u9001\uff1a\u670d\u52d9\u5668\u53ef\u4ee5\u4e3b\u52d5\u63a8\u9001\u8cc7\u6e90\u5230\u5ba2\u6236\u7aef\uff0c\u9032\u4e00\u6b65\u52a0\u5feb\u52a0\u8f09\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%ae%89%e8%a3%9dapache%e8%88%87mod_proxy_http2-kbSMIdlhea\">\u5b89\u88ddApache\u8207mod_proxy_http2<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684\u4f3a\u670d\u5668\u4e0a\u5df2\u7d93\u5b89\u88dd\u4e86Apache\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88ddApache\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install apache2<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u63a5\u4e0b\u4f86\u9700\u8981\u555f\u7528mod_proxy\u548cmod_proxy_http2\u6a21\u7d44\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u555f\u7528\u9019\u4e9b\u6a21\u7d44\uff1a<\/p>\n<pre><code>sudo a2enmod proxy\nsudo a2enmod proxy_http\nsudo a2enmod http2<\/code><\/pre>\n<p>\u555f\u7528\u6a21\u7d44\u5f8c\uff0c\u91cd\u555fApache\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo systemctl restart apache2<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%aeapache%e4%bb%a5%e6%94%af%e6%8c%81http-2-kbSMIdlhea\">\u914d\u7f6eApache\u4ee5\u652f\u6301HTTP\/2<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u914d\u7f6eApache\u4ee5\u652f\u6301HTTP\/2\u3002\u6253\u958bApache\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc\/etc\/apache2\/apache2.conf\u6216\/etc\/httpd\/conf\/httpd.conf\uff0c\u7136\u5f8c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\n    ServerName example.com\n    Redirect permanent \/ https:\/\/example.com\/\n&lt;\/VirtualHost&gt;\n\n&lt;VirtualHost *:443&gt;\n    ServerName example.com\n    SSLEngine on\n    SSLCertificateFile \/path\/to\/certificate.crt\n    SSLCertificateKeyFile \/path\/to\/private.key\n\n    Protocols h2 http\/1.1\n\n    ProxyPass \/ http:\/\/backend-server\/\n    ProxyPassReverse \/ http:\/\/backend-server\/\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0c\u8acb\u5c07example.com\u66ff\u63db\u70ba\u4f60\u7684\u57df\u540d\uff0c\u4e26\u5c07SSL\u8b49\u66f8\u7684\u8def\u5f91\u66ff\u63db\u70ba\u5be6\u969b\u7684\u8b49\u66f8\u8def\u5f91\u3002\u9019\u6bb5\u914d\u7f6e\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5c07\u6240\u6709HTTP\u8acb\u6c42\u91cd\u5b9a\u5411\u5230HTTPS\uff0c\u4e26\u8a2d\u7f6eHTTP\/2\u5354\u8b70\u3002<\/p>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e9%85%8d%e7%bd%ae-kbSMIdlhea\">\u6e2c\u8a66\u914d\u7f6e<\/h2>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5Apache\u7684\u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo apachectl configtest<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u5247\u53ef\u4ee5\u91cd\u555fApache\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart apache2<\/code><\/pre>\n<p>\u6700\u5f8c\uff0c\u4f7f\u7528\u700f\u89bd\u5668\u6216\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5982curl\uff09\u4f86\u6e2c\u8a66HTTP\/2\u662f\u5426\u6b63\u5e38\u904b\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\uff1a<\/p>\n<pre><code>curl -I -s --http2 https:\/\/example.com<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u4f60\u61c9\u8a72\u80fd\u770b\u5230HTTP\/2\u7684\u97ff\u61c9\u6a19\u982d\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-kbSMIdlhea\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u4f60\u5df2\u7d93\u6210\u529f\u5728Apache\u4e2d\u8a2d\u7f6e\u4e86mod_proxy_http2\uff0c\u4e26\u914d\u7f6e\u4e86HTTP\/2\u7684\u53cd\u5411\u4ee3\u7406\u529f\u80fd\u3002\u9019\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u4f60\u7684Apache\u4f3a\u670d\u5668\uff0c\u4eab\u53d7\u66f4\u5feb\u7684\u52a0\u8f09\u901f\u5ea6\u548c\u7a69\u5b9a\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u8a2d\u7f6eApache\u4f3a\u670d\u5668\u8207mod_proxy_http2\uff0c\u9069\u5408\u65b0\u624b\u7684\u8a73\u7d30\u6559\u7a0b\uff0c\u8f15\u9b06\u638c\u63e1\u9ad8\u6548\u7684\u7db2\u9801\u4ee3\u7406\u6280\u8853\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-40459","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/40459","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=40459"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/40459\/revisions"}],"predecessor-version":[{"id":40460,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/40459\/revisions\/40460"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=40459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=40459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=40459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}