毎度、apacheのソースインストールに執着してます。
今回はhttp2を有効にしてCentOS7にソースインストールします。
id=”目次”>目次
下準備
とりあえず必要そうなパッケージをインストールしておきます。
# yum install pcre-devel # yum install openssl-devel # yum install zlib-devel # yum install expat-devel
続いてapacheとaprとかをダウンロード&配置します。
# wget http://ftp.yz.yamagata-u.ac.jp/pub/network/apache//httpd/httpd-2.4.33.tar.gz # tar xvfz httpd-2.4.33.tar.gz # wget http://ftp.kddilabs.jp/infosystems/apache//apr/apr-1.6.3.tar.gz # wget http://ftp.kddilabs.jp/infosystems/apache//apr/apr-util-1.6.1.tar.gz # tar xvfz apr-util-1.6.1.tar.gz # tar xvfz apr-1.6.3.tar.gz # mv apr-1.6.3 httpd-2.4.33/srclib/apr # mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util
apacheのインストール(configure失敗)
# ./configure --prefix=/usr/local/apache-2.4.33 --with-mpm=worker --enable-http2 --with-included-apr <中略> checking for OpenSSL... (cached) yes setting MOD_LDFLAGS to " -lssl -lcrypto -lrt -lcrypt -lpthread -ldl" setting MOD_CFLAGS to " " setting MOD_CPPFLAGS to "-DH2_OPENSSL" checking for nghttp2... checking for user-provided nghttp2 base directory... none checking for pkg-config along ... checking for nghttp2 version >= 1.2.1... FAILED configure: WARNING: nghttp2 version is too old no checking whether to enable mod_http2... configure: error: mod_http2 has been requested but can not be built due to prerequisite failures
無事失敗してくれました。いい感じです。
nghttp2のインストール
エラーにあるように、nghttp2が無い or 古いようですのでそちらを先にインストールします。
githubに最新版があるのでそちらをインストールします。
# wget https://github.com/nghttp2/nghttp2/releases/download/v1.32.0/nghttp2-1.32.0.tar.gz # tar xvfz nghttp2-1.32.0.tar.gz # cd nghttp2-1.32.0/
gitからビルドする方法もあるのですが、とりあえず今回はconfigure使っていきます。
# ./configure # make # make install # echo /usr/local/lib >> /etc/ld.so.conf # ldconfig
apacheのインストール2
2回目のチャレンジです。
# cd ../httpd-2.4.33/ # ./configure --prefix=/usr/local/apache-2.4.33 --with-mpm=worker --enable-http2 --with-included-apr
今度はうまくいきました。
apacheの設定
インストール後は設定していきます。デフォルトではmoduleのhttp2が無効になっているので、こちらのコメントを外します。
# vim /usr/local/apache2/conf/httpd.conf LoadModule http2_module modules/mod_http2.so
virtualhostごとにhttp2を有効にしたかったら各virtualhostディレクティブに記載が必要ですが、今回は全体に適用するつもりなので、以下設定もhttpd.confの末尾にでも追加します。
# vim /usr/local/apache2/conf/httpd.conf <IfModule http2_module> Protocols h2 http/1.1 </IfModule>
上記でhttp2とhttp1.1の両方が有効になります。
ざっくりですが、こんな感じで。気がついたらなにか追加します。