全般的にコンパイルして忙しそうな解説しかないので、パッケージで対応できる範囲を明確にするために VirtualBox + CentOS 7 でパッケージだけで動作検証。
現時点では OpenSSL の RPM パッケージは 1.0.1 までしか見つからないが、RHEL 7.4 で OpenSSL 1.0.2 が利用できるようになるようである。 1
CentOS 7.4 から OpenSSL が 1.0.2 にバージョンアップされたため、完全にパッケージのみで Apache を HTTP/2 に対応させることが可能になりました。
パッケージのみで CentOS の Apache を HTTP/2 対応にする - Qiita
インストール
nghttp2
yum -y install epel-release && yum -y install nghttp2
nghttp2 は 1.7.1 と多少バージョンが古いが EPEL リポジトリにパッケージが用意されている。
依存関係で libev と libnghttp2 もインストールされる。
Apache HTTP Server
mod_http2 モジュールは Apache 2.4.17 以降で利用できるが、CentOS の標準リポジトリでは 2.4.6 がインストールされるため利用できない。
Apache 2.4.17 以降をパッケージでインストールできるのは以下の2つ。
- RHSCL リポジトリ httpd24 パッケージ Apache 2.4.18
- IUS リポジトリ httpd24u パッケージ Apache 2.4.25
RHSCL (Red Hat Software Collection 2.3)
yum -y install centos-release-scl
yum -y install httpd24 && source scl_source enable $_
echo -e '#!/bin/bash\nsource scl_source enable httpd24' > /etc/profile.d/httpd24.sh
ln -s {/opt/rh/httpd24/root,}/etc/httpd
ln -s {/opt/rh/httpd24/root,}/var/www
ln -s /{usr/lib/systemd/system/httpd24-,etc/systemd/system/}httpd.service
systemctl daemon-reload
IUS
curl -s https://setup.ius.io/ | sh
yum -y install httpd24u
firewalld
firewall-cmd --add-service=http{,s} --permanent && firewall-cmd --reload
h2c
cat << "_EOF_" > /etc/httpd/conf.d/http2.conf
<IfModule http2_module>
Protocols h2 h2c http/1.1
H2Direct on
</IfModule>
_EOF_
systemctl start httpd && systemctl enable $_
確認
HTTP/2の動作確認 - Apache 2.4系でHTTP/2対応サーバを構築してみるテスト。を参考に以下の通り確認する。
アップグレード
nghttp -uv http://localhost | grep Upgrade
[ 0.000] HTTP Upgrade request
connection: Upgrade, HTTP2-Settings
[ 0.001] HTTP Upgrade response
Upgrade: h2c
Connection: Upgrade
[ 0.001] HTTP Upgrade success
ダイレクトモード
nghttp -v http://localhost | grep "SETTINGS\|HEADERS"
[ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
[SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[ 0.000] send HEADERS frame <length=34, flags=0x25, stream_id=13>
; END_STREAM | END_HEADERS | PRIORITY
[ 0.001] recv SETTINGS frame <length=6, flags=0x00, stream_id=0>
[SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
[ 0.001] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
[ 0.001] recv HEADERS frame <length=114, flags=0x04, stream_id=13>
; END_HEADERS
[ 0.001] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
ブラウザ
Upgrade:h2,h2c
デベロッパーツールで HTTP レスポンスヘッダーを確認すると上記の出力がある。