Apache2.4.17でHTTP/2対応

先週バージョンアップしたApache httpd。HTTP/2に正式対応ってことで作業ログ。

nghttp2をインストール

apacheはmod_http2というモジュールでHTTP/2に対応していますが、このモジュールはlibnghttp2.soに依存しています。ってことでnghttp2をインストール。

gitからclone
$ git clone https://github.com/tatsuhiro-t/nghttp2.git
コンパイル、リンク、インストール
$ cd nghttp2
$ ./configure --prefix=/usr
$ make -j8
# make install
参考までにchefのレシピ

上記の作業のために作成したchefレシピはこちら。attributesでmakedirを適当に定義。

makedir = node['nghttp2']['makedir']

git "#{makedir}" do
  user "hoge"
  group "fuga"
  revision "master"
  repository "https://github.com/tatsuhiro-t/nghttp2.git"
  action :sync
end

script "make_nghttp2" do
  interpreter "bash"
  user "hoge"
  group "fuga"
  cwd "#{makedir}"
  code <<-EOH
    autoreconf -i
    automake
    autoconf
    ./configure --prefix=/usr
    make -j8
  EOH
  notifies :run,'script[install_nghttp2]'
end

script "install_nghttp2" do
  interpreter "bash"
  user "root"
  group "root"
  cwd "#{makedir}"
  code <<-EOH
    make install
  EOH
  action :nothing
end

ldconfigでlibnghttp2.soを認識させる

# ldconfig

httpdを再コンパイル

"--enable-http2"をつけてconfigure。それからmake,install。

$ cd httpd-2.4.17
$ ./configure (その他たくさん) --enable-http2
$ make -j8
# make install

apache設定ファイル編集

mod_http2.soをロードする行と、Protocolsを指定。
以下の2行を追加。

LoadModule http2_module modules/mod_http2.so
Protocols h2 http/1.1

確認

文法チェック。

# /usr/local/apache2/bin/apachectl -t
Syntax OK

libnghttp2.so.14が見えないとかなんとかいってきたら、ldconfigあたりを調整してあげる。上記と同じように nghttp2をコンパイルするときに--prefix=/usrでconfigureしていれば問題ないはず。

apache再起動

# /usr/local/apache2/bin/apachectl restart