{"id":1083,"date":"2019-08-20T13:47:41","date_gmt":"2019-08-20T05:47:41","guid":{"rendered":"https:\/\/www.behindgfw.com\/archives\/?p=1083"},"modified":"2019-08-20T13:47:41","modified_gmt":"2019-08-20T05:47:41","slug":"provide-http2-support-for-apache","status":"publish","type":"post","link":"https:\/\/www.behindgfw.com\/archives\/2019\/08\/provide-http2-support-for-apache.html","title":{"rendered":"\u4e3aapache\u63d0\u4f9bhttp2\u652f\u6301"},"content":{"rendered":"<p>\u622a\u81f32015\u5e74\u672b\uff0c\u4e3b\u8981\u7684\u6d4f\u89c8\u5668\u7684\u6700\u65b0\u7248\u672c\u5df2\u7ecf\u652f\u6301HTTP\/2\u534f\u8bae\u3002\u5176\u4e2d\uff1aGoogle Chrome\u3001Mozilla Firefox\u3001Microsoft Edge\u548cOpera\u5df2\u652f\u6301HTTP\/2\uff0c\u5e76\u9ed8\u8ba4\u542f\u7528\u3002Internet Explorer\u81eaIE 11\u5f00\u59cb\u652f\u6301HTTP\/2\uff0c\u5e76\u9884\u8bbe\u542f\u7528\u3002<br \/>\n\u4e0b\u9762\u7b80\u8ff0ubuntu16.04 \u4e0bapache\u4e0b\u5f00\u542fhttp2\u7684\u51e0\u79cd\u65b9\u6cd5\u3002<\/p>\n<p>1\u3001\u4f7f\u7528<a href=\"https:\/\/launchpad.net\/~ondrej\" target=\"_blank\" rel=\"noopener noreferrer\">ppa:ondrej<\/a>\u6e90<br \/>\nUBUNTU 16.04\u9ed8\u8ba4\u6e90\u91cc\u7684APACHE\u4e3a2.4.18\u7248\uff0c\u6ca1\u6709HTTP2\u6a21\u5757,\u76f4\u63a5\u542f\u7528HTTP2\u4f1a\u627e\u4e0d\u5230\u6a21\u5757\u3002<\/p>\n<blockquote><p>a2enmod http2<br \/>\nERROR: Module http2 does not exist!<\/p><\/blockquote>\n<p>ppa:ondrej\u662f\u4e00\u4e2a\u6bd4\u8f83\u77e5\u540d\u7684\u6e90\uff0c\u6700\u65b0\u7684apache\u7248\u672c\u662f2.4.38<\/p>\n<blockquote><p>sudo add-apt-repository ppa:ondrej\/apache2<br \/>\nsudo apt update<br \/>\nsudo apt install apache2<br \/>\na2enmod http2<\/p><\/blockquote>\n<p>\u5b89\u88c5<a href=\"https:\/\/www.behindgfw.com\/archives\/2019\/07\/lets-encrypt-postponed-deploy-isrg-root.html\" target=\"_blank\" rel=\"noopener noreferrer\">Let\u2019s Encrypt<\/a>\uff0c\u5728\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u7684SERVERNAME\u4e0b\u6dfb\u52a0\u4e00\u884c:<\/p>\n<blockquote><p>&lt;VirtualHost x.x.x.x:443&gt;<br \/>\n<strong>Protocols h2 http\/1.1<\/strong><\/p>\n<p>\u2026<br \/>\n&lt;\/VirtualHost&gt;<\/p><\/blockquote>\n<p>\u91cd\u542fapache<\/p>\n<blockquote><p>service apache2 restart<\/p><\/blockquote>\n<p>2\u3001\u7f16\u8bd1apache 2.4.41<br \/>\n\u6211\u4eec\u9700\u8981\u5b89\u88c5 nghttp2\uff08http2 \u7684 C \u8bed\u8a00\u5e93\uff09<\/p>\n<blockquote><p>#\u5b89\u88c5\u7f16\u8bd1\u5de5\u5177\u7b49<br \/>\nsudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config \\<br \/>\nzlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev \\<br \/>\nlibjemalloc-dev cython python3-dev python-setuptools libpcre3 libpcre3-dev openssl<\/p>\n<p>#\u7f16\u8bd1\u5b89\u88c5nghttp2<br \/>\ngit clone https:\/\/github.com\/tatsuhiro-t\/nghttp2.git<br \/>\ncd nghttp2<br \/>\nautoreconf -i<br \/>\nautomake<br \/>\nautoconf<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install<\/p><\/blockquote>\n<p>\u5b89\u88c5PRCE<\/p>\n<blockquote><p>#apt-get install libpcre3 libpcre3-dev<\/p>\n<p>#\u5df2\u7ecf\u5b89\u88c5<\/p><\/blockquote>\n<p>\u7f16\u8bd1apache<\/p>\n<blockquote><p>cd ~<br \/>\nwget http:\/\/archive.apache.org\/dist\/httpd\/httpd-2.4.18.tar.gz<br \/>\nwget https:\/\/www-us.apache.org\/dist\/apr\/apr-1.7.0.tar.gz<br \/>\nwget https:\/\/www-us.apache.org\/dist\/apr\/apr-util-1.6.1.tar.gz<br \/>\ntar xzf httpd-2.4.18.tar.gz<br \/>\ntar xzf apr-1.7.0.tar.gz<br \/>\ntar xzf apr-util-1.6.1.tar.gz<br \/>\nmv apr-1.7.0 httpd-2.4.18\/srclib\/apr<br \/>\nmv apr-util-1.6.1 httpd-2.4.18\/srclib\/apr-util<br \/>\ncd httpd-2.4.18<\/p>\n<p>.\/configure &#8211;prefix=\/usr\/local\/apache2.4.18 &#8211;enable-so &#8211;enable-deflate=shared &#8211;enable-ssl=shared &#8211;enable-expires=shared &#8211;enable-headers=shared &#8211;enable-rewrite=shared &#8211;enable-static-support &#8211;with-included-apr &#8211;with-mpm=event &#8211;enable-http2<\/p>\n<p>make &amp;&amp; make install<\/p>\n<p>#\u6dfb\u52a0\u542f\u52a8\u811a\u672capache2\u5230service<\/p>\n<p>sudo cp \/usr\/local\/apache2.4.18\/bin\/apachectl \/etc\/init.d\/apache2<\/p>\n<p>cd ..<\/p>\n<p>#\u6dfb\u52a0apache2\u5230\u73af\u5883\u53d8\u91cf<br \/>\nsudo echo &#8216;export PATH=$PATH:\/usr\/local\/apache2.4.18\/bin&#8217; &gt; .\/apache2.sh<br \/>\nsudo chmod a+x apache2.sh<\/p>\n<p># \u62f7\u8d1d\u811a\u672c\u81f3\u76ee\u5f55<br \/>\nsudo cp apache2.sh \/etc\/profile.d<\/p>\n<p># \u66f4\u65b0\u811a\u672c\u72b6\u6001<br \/>\nsource \/etc\/profile.d\/apache2.sh<br \/>\n#\u6dfb\u52a0apache2\u5230\u5f00\u673a\u542f\u52a8\u9879<br \/>\nsudo nano\u00a0\/etc\/rc.local<\/p>\n<p>#\u5c06\/etc\/profile.d\/apache2.sh\u6dfb\u52a0\u5230exit 0\u4e4b\u524d<\/p>\n<p>\/etc\/profile.d\/apache2.sh<\/p>\n<p>exit 0<\/p><\/blockquote>\n<p>#\u542f\u52a8apache2<\/p>\n<blockquote><p><strong><b>sudo systemctl start apache2<\/b><\/strong><\/p>\n<p><strong>\u4e0d\u8fc7\u56e0\u4e3a\u7f16\u8bd1\u5b89\u88c5\u7684apache2\u8bbe\u7f6e\u6587\u4ef6\u96c6\u4e2d\u653e\u5728httpd.conf\uff0c\u4f7f\u7528\u8d77\u6765\u4e0d\u662f\u5f88\u65b9\u4fbf\uff0c\u8fd8\u8981\u4e00\u5806\u8bbe\u7f6e\uff0c\u4e0d\u63a8\u8350\u4f7f\u7528\uff0c\u91cd\u70b9\u662f\u5229\u7528\u7f16\u8bd1\u597d\u7684http2.so\u6a21\u5757\u3002<\/strong><\/p>\n<p>\u4ee5\u4e0a\u5728linode\u7f16\u8bd1\u6210\u529f\uff0c\u4e0d\u540cIDC\u53ef\u80fd\u7a0d\u6709\u4e0d\u540c\uff0c\u8bf7\u81ea\u884c\u7504\u522b\u3002<\/p><\/blockquote>\n<p>3\u3001\u76f4\u63a5\u4f7f\u7528\u4e0a\u4e00\u6b65\u7f16\u8bd1\u597d\u7684http2.so\u6a21\u5757\uff0c<strong>\u63a8\u8350<\/strong><\/p>\n<blockquote><p>sudo cp \/usr\/local\/apache2.4.18\/modules\/mod_http2.so \/usr\/lib\/apache2\/modules\/<\/p><\/blockquote>\n<p>\u7136\u540e\u4e3aHTTP2\u6a21\u5757\u7f16\u5199\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6:<\/p>\n<blockquote><p>sudo nano \/etc\/apache2\/mods-available\/http2.load<\/p><\/blockquote>\n<p>\u5728\u5176\u4e2d\u5199\u5165\u4ee5\u4e0b:<\/p>\n<blockquote><p>LoadModule http2_module \/usr\/lib\/apache2\/modules\/mod_http2.so<\/p>\n<p>LogLevel http2:info<\/p><\/blockquote>\n<p>\u6ce8\u610f\uff1a<\/p>\n<blockquote><p>nghttp2\u8fd8\u662f\u8981\u5b89\u88c5\u7684\uff0c\u8981\u4e0dapache2\u91cd\u542f\u4f1a\u62a5\u9519\u3002\u540c\u65f6\u4e0d\u8981\u5fd8\u8bb0\u8bbe\u7f6eVirtualHost<\/p>\n<p>&lt;VirtualHost x.x.x.x:443&gt;<br \/>\n<strong>Protocols h2 http\/1.1<\/strong><\/p>\n<p>\u2026<br \/>\n&lt;\/VirtualHost&gt;<\/p><\/blockquote>\n<p>\u6700\u540e\u542f\u7528HTTP2\u6a21\u5757:<\/p>\n<blockquote><p>sudo service apache2 restart<br \/>\nsudo a2enmod http2<\/p>\n<p>sudo service apache2 restart<\/p><\/blockquote>\n<p>\u5927\u529f\u544a\u6210\u3002<\/p>\n<p>4\u3001\u53c2\u89c1<\/p>\n<p><a href=\"https:\/\/new.blog.cloudflare.com\/tools-for-debugging-testing-and-using-http-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/new.blog.cloudflare.com\/tools-for-debugging-testing-and-using-http-2\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u622a\u81f32015\u5e74\u672b\uff0c\u4e3b\u8981\u7684\u6d4f\u89c8\u5668\u7684\u6700\u65b0\u7248\u672c\u5df2\u7ecf\u652f\u6301HTTP\/2\u534f\u8bae\u3002\u5176\u4e2d\uff1aGoogle Chrome\u3001Mozil [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[34,83,32,84],"class_list":["post-1083","post","type-post","status-publish","format-standard","hentry","category-webdev","tag-host","tag-http2","tag-linux","tag-ssl"],"_links":{"self":[{"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/posts\/1083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":11,"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"predecessor-version":[{"id":1101,"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/posts\/1083\/revisions\/1101"}],"wp:attachment":[{"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.behindgfw.com\/archives\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}