h2o構築作業メモ

http2を理解するためにh2oをインストール・起動しました。

構築する環境

h2oをインストール

# root ユーザで実行
# https://github.com/h2o/h2o/releases の tarファイルのURLから
wget https://github.com/h2o/h2o/archive/v1.6.3.tar.gz
tar xzf v1.6.3.tar.gz
cd h20-1.6.3
cmake .
make
sudo make install

h2oを設定する

最終的な設定ファイル郡

root@precise64:/usr/local/etc# tree h2o/
h2o/
|-- access-log
|-- cert.csr
|-- cert.key
|-- cert.pem
|-- error-log
|-- h2o.conf
|-- index.html
`-- pid-file

自己証明書の作成

$ mkdir /usr/local/etc/h2o/
$ cd /usr/local/etc/h2o/
$ openssl genrsa 2048 > cert.key
$ openssl req -new -key cert.key  > cert.csr
$ openssl x509 -days 3650 -req -signkey cert.key < cert.csr > cert.pem

各種起動に必要なファイルを作成

$ touch /usr/local/etc/h2o/access-log
$ touch /usr/local/etc/h2o/error-log
$ touch /usr/local/etc/h2o/pid-file

confファイルの作成

$ cd /usr/local/etc/h2o/
$ vi h2o.conf 
#----------------------
 1 user: root
 2 hosts:
 3   "*":
 4     listen:
 5       port: 443
 6       ssl:
 7         certificate-file: /usr/local/etc/h2o/cert.pem
 8         key-file:  /usr/local/etc/h2o/cert.key
 9     paths:
 10       "/":
 11         file.dir: /usr/local/etc/h2o/
 12 
 13 access-log: /usr/local/etc/h2o/access-log
 14 error-log: /usr/local/etc/h2o/error-log
 15 pid-file: /usr/local/etc/h2o/pid-file

index.htmlの作成

$ cd /usr/local/etc/h2o
$ vi index.html 
-----------------------------
<html>
<head>
        <title>hello, h2o! </title>
</head>
<body>
        hello, h2o!
</body>
<html>

起動と終了

# 起動前のテスト
$ sudo /usr/local/bin/h2o -m test -c /usr/local/etc/h2o/h2o.conf
# Backgroundプロセスとして起動
$ sudo /usr/local/bin/h2o -m daemon -c /usr/local/etc/h2o/h2o.conf 
# 停止
$ sudo kill -TERM `cat /usr/local/etc/h2o/pid-file`

アクセス

enter image description here

その他にやったこと

cmake をソースからインストール

apt-getでインストールしたcmakeのバージョンが古かったためソースコードからインストール

# rootユーザで実行
sudo apt-get install build-essential
wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz --no-check-certificate
tar xf cmake-3.2.2.tar.gz
cd cmake-3.2.2
./configure
make
make install

参考