{"id":34279,"date":"2024-09-30T23:51:28","date_gmt":"2024-09-30T15:51:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/34279\/"},"modified":"2024-09-30T23:51:28","modified_gmt":"2024-09-30T15:51:28","slug":"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8mod_proxy_http2%e9%80%b2%e8%a1%8chttp-2%e4%bb%a3%e7%90%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/34279\/","title":{"rendered":"Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528mod_proxy_http2\u9032\u884cHTTP\/2\u4ee3\u7406"},"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_proxy_http2%e9%80%b2%e8%a1%8chttp-2%e4%bb%a3%e7%90%86-zEbKItyifA\">Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528mod_proxy_http2\u9032\u884cHTTP\/2\u4ee3\u7406<\/h1>\n<p>\u96a8\u8457\u7db2\u969b\u7db2\u8def\u6280\u8853\u7684\u5feb\u901f\u767c\u5c55\uff0cHTTP\/2\u4f5c\u70baHTTP\/1.1\u7684\u7e7c\u4efb\u8005\uff0c\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u6027\u80fd\u548c\u66f4\u4f4e\u7684\u5ef6\u9072\u3002Apache\u4f5c\u70ba\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u652f\u6301HTTP\/2\u7684\u529f\u80fd\uff0c\u4e26\u4e14\u53ef\u4ee5\u901a\u904emod_proxy_http2\u6a21\u7d44\u4f86\u5be6\u73feHTTP\/2\u4ee3\u7406\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u914d\u7f6eApache\u4ee5\u4f7f\u7528mod_proxy_http2\u9032\u884cHTTP\/2\u4ee3\u7406\uff0c\u4e26\u4ecb\u7d39\u76f8\u95dc\u7684\u5b89\u5168\u7b56\u7565\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmod_proxy_http2%ef%bc%9f-zEbKItyifA\">\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\u4ee3\u7406\u4f3a\u670d\u5668\u3002\u9019\u610f\u5473\u8457Apache\u53ef\u4ee5\u63a5\u6536HTTP\/2\u8acb\u6c42\uff0c\u4e26\u5c07\u5176\u8f49\u767c\u5230\u5f8c\u7aef\u4f3a\u670d\u5668\u3002\u9019\u7a2e\u65b9\u5f0f\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6027\u80fd\uff0c\u9084\u80fd\u5920\u5229\u7528HTTP\/2\u7684\u591a\u8def\u5fa9\u7528\u7279\u6027\uff0c\u6e1b\u5c11\u5ef6\u9072\u3002<\/p>\n<h2 id=\"%e9%85%8d%e7%bd%aeapache%e4%bb%a5%e4%bd%bf%e7%94%a8mod_proxy_http2-zEbKItyifA\">\u914d\u7f6eApache\u4ee5\u4f7f\u7528mod_proxy_http2<\/h2>\n<p>\u8981\u555f\u7528mod_proxy_http2\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fddApache\u5df2\u7d93\u5b89\u88dd\u4e86\u8a72\u6a21\u7d44\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\uff1a<\/p>\n<pre><code>apachectl -M | grep proxy_http2<\/code><\/pre>\n<p>\u5982\u679c\u672a\u5b89\u88dd\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u555f\u7528\uff1a<\/p>\n<pre><code>sudo a2enmod proxy_http2<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u76f8\u61c9\u7684\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\n    ServerName example.com\n\n    # \u5c07HTTP\u8acb\u6c42\u91cd\u5b9a\u5411\u5230HTTPS\n    Redirect \/ 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    # \u555f\u7528HTTP\/2\n    Protocols h2 http\/1.1\n\n    # \u8a2d\u7f6e\u4ee3\u7406\n    ProxyPass \/ http:\/\/backend-server\/\n    ProxyPassReverse \/ http:\/\/backend-server\/\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5-zEbKItyifA\">\u5b89\u5168\u7b56\u7565<\/h2>\n<p>\u5728\u914d\u7f6emod_proxy_http2\u6642\uff0c\u5b89\u5168\u6027\u662f\u4e0d\u53ef\u5ffd\u8996\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\u7684\u5b89\u5168\u7b56\u7565\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528HTTPS\uff1a<\/strong>\u78ba\u4fdd\u6240\u6709\u7684HTTP\/2\u6d41\u91cf\u90fd\u901a\u904eHTTPS\u9032\u884c\u52a0\u5bc6\uff0c\u9019\u6a23\u53ef\u4ee5\u9632\u6b62\u4e2d\u9593\u4eba\u653b\u64ca\u3002<\/li>\n<li><strong>\u9650\u5236\u4ee3\u7406\u7684\u4f86\u6e90\uff1a<\/strong>\u4f7f\u7528<code>ProxyRequests Off<\/code>\u4f86\u7981\u7528\u6b63\u5411\u4ee3\u7406\uff0c\u4e26\u4f7f\u7528<code>Require<\/code>\u6307\u4ee4\u4f86\u9650\u5236\u54ea\u4e9bIP\u53ef\u4ee5\u8a2a\u554f\u4ee3\u7406\u3002<\/li>\n<li><strong>\u8a2d\u7f6e\u9632\u706b\u7246\uff1a<\/strong>\u78ba\u4fdd\u53ea\u6709\u5fc5\u8981\u7684\u7aef\u53e3\uff08\u598280\u548c443\uff09\u5c0d\u5916\u958b\u653e\uff0c\u4e26\u4f7f\u7528\u9632\u706b\u7246\u4f86\u904e\u6ffe\u4e0d\u5fc5\u8981\u7684\u6d41\u91cf\u3002<\/li>\n<li><strong>\u76e3\u63a7\u548c\u65e5\u8a8c\uff1a<\/strong>\u5b9a\u671f\u6aa2\u67e5Apache\u7684\u65e5\u8a8c\u6587\u4ef6\uff0c\u76e3\u63a7\u53ef\u7591\u6d3b\u52d5\uff0c\u4e26\u53ca\u6642\u63a1\u53d6\u884c\u52d5\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-zEbKItyifA\">\u7d50\u8ad6<\/h2>\n<p>\u4f7f\u7528mod_proxy_http2\u9032\u884cHTTP\/2\u4ee3\u7406\u4e0d\u50c5\u80fd\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\uff0c\u9084\u80fd\u5229\u7528HTTP\/2\u7684\u5148\u9032\u7279\u6027\u3002\u7136\u800c\uff0c\u5b89\u5168\u6027\u59cb\u7d42\u662f\u914d\u7f6e\u904e\u7a0b\u4e2d\u7684\u91cd\u4e2d\u4e4b\u91cd\u3002\u901a\u904e\u9075\u5faa\u4e0a\u8ff0\u5b89\u5168\u7b56\u7565\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd\u60a8\u7684Apache\u4f3a\u670d\u5668\u5728\u63d0\u4f9b\u9ad8\u6548\u80fd\u7684\u540c\u6642\uff0c\u4e5f\u80fd\u4fdd\u6301\u5b89\u5168\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc<em><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/em>\u548c<em><a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a><\/em>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Apache\u5b89\u5168\u7b56\u7565\uff0c\u4f7f\u7528mod_proxy_http2\u5b9e\u73b0\u5b89\u5168\u9ad8\u6548\u7684HTTP\/2\u4ee3\u7406\uff0c\u63d0\u5347\u7f51\u7ad9\u6027\u80fd\u4e0e\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-34279","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/34279","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=34279"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/34279\/revisions"}],"predecessor-version":[{"id":34280,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/34279\/revisions\/34280"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=34279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=34279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=34279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}