LoginSignup
5
6

More than 5 years have passed since last update.

apacheでhttp2を使う(h2c妥協版)

Last updated at Posted at 2015-12-25

apacheでhttp2を試してみようとして、
httpでは動いたものの、httpsでは上手くいかず
やむなく妥協したときの備忘録的メモです。

事前準備

コンパイルにgccが必要なため、入れておく。

# yum install gcc

apacheのmod_http2を動かすためにはnghttp2が必要なので、インストール。

# tar zxvf nghttp2-1.5.0.tar.gz
# cd nghttp2-1.5.0
# ./configure
# make
# make install

確認用にhttp2対応したcurlもインストールしておく。

# tar zxvf curl-7.46.0.tar.gz
# cd curl-7.46.0
# ./configure
# make
# make install

apacheのインストール

aprとapr-utilが必要になるので、先にインストールしておく。
(何なのかは良くわからない)

# tar zxvf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure
# make
# make install
# tar zxvf apr-util-1.5.4
# cd apr-util-1.5.4
# ./configure --with-apr=/usr/local/apr/
# make
# make install

pcreとopensslも必要なので、インストール。
(develの方)

# yum install pcre-devel
# yum install openssl-devel

apacheをインストール。

# tar zxvf httpd-2.4.17.tar.gz
# cd httpd-2.4.17
# ./configure --enable-http2 --enable-ssl
# make
# make install

configure時に、http2が有効になっていることを確認しておくこと。
(重要)

HTTP2 support:    enabled (nghttp2)

http2を使うための設定

mod_http2を有効にするための設定(httpd.conf)

# vi /usr/local/apache2/conf/httpd.conf
## mod_http2のLoadModuleをアンコメント
LoadModule http2_module modules/mod_http2.so

## mod_http2を有効にするための設定(h2c)
<IfModule http2_module>
        Protocols h2c http/1.1
</IfModule>

apacheを再起動する。

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

動作確認

プロトコルにhttp2を指定して、curlでアクセスしてみると。。

# /usr/local/bin/curl -v --http2 http://localhost

以下のレスポンスヘッダが返ってきた。

* Rebuilt URL to: http://localhost/
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.46.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAAQAAP__
>
< HTTP/1.1 101 Switching Protocols
< Upgrade: h2c
< Connection: Upgrade
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* TCP_NODELAY set
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=27
< HTTP/2.0 200
< date:Fri, 25 Dec 2015 13:37:14 GMT
< server:Apache/2.4.17 (Unix)
< last-modified:Mon, 11 Jun 2007 18:53:14 GMT
< etag:"2d-432a5e4a73a80"
< accept-ranges:bytes
< content-length:45
< content-type:text/html
<
<html><body><h1>It works!</h1></body></html>

細かく見てみると。。

< HTTP/1.1 101 Switching Protocols
< Upgrade: h2c
・・・
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=27
< HTTP/2.0 200

確かに、HTTP2.0でレスポンスが返ってきている。
mod_http2では、HTTP1.1をHTTP2.0に
プロトコル変換するような動きになるようだ。

h2cの設定ではhttpがhttp2に変換されるとのこと。

http2ってssl必須だったような気がするが、
mod_http2はhttpでも使えるということなのだろうか。

httpsで動かすには別途sslの設定が必要だが、
なぜか上手く動かなかったので、
また再挑戦しよう。

以上m(_ _)m

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6