あみだくじです。
このブログは WordPress で動いていて、Webサーバは H2O、そして最近はすべて HTTPS にする流れのようなので Let’s Encrypt で発行した証明書を使って HTTPS にしています。
証明書の発行は以下でできます。とても簡単。
git clone git://github.com/letsencrypt/letsencrypt.git
cd letsencrypt
./letsencrypt-auto --help
./letsencrypt-auto certonly --standalone -d shareable.house
今回 WordPress を Apache ではないサーバで動かすので、certonly --standalone
にしています。
Let’s Encrypt の証明書は3ヶ月で期限が切れてしまうので、cron などを使って自動更新の設定をすべきですがまだしていません。自動更新の仕組みはいま Let’s Encrypt 側が作っているみたいなのでそれを待ちます。
Webサーバは H2O で、h2o.conf
は下のような感じになっています。
pid-file: /var/run/h2o.pid
error-log: /var/log/h2o/error.log
access-log: /var/log/h2o/access.log
user: wp
file.custom-handler:
extension: .php
fastcgi.spawn: "PHP_FCGI_CHILDREN=10 exec /usr/bin/php-cgi"
file.index: [ 'index.php', 'index.html' ]
hosts:
"shareable.house:80":
listen:
host: 0.0.0.0
port: 80
paths:
"/":
redirect: https://shareable.house/
"shareable.house:443":
listen:
host: 0.0.0.0
port: 443
ssl:
key-file: /etc/letsencrypt/live/shareable.house/privkey.pem
certificate-file: /etc/letsencrypt/live/shareable.house/fullchain.pem
paths:
"/":
file.dir: /home/wp/shareable.house
redirect:
url: /index.php/
internal: YES
status: 307
これだけでちゃんと PHP のコードが処理されるようになります。とても簡単。そして HTTPS なので何もしなくても HTTP/2 が有効になりいい感じです。
ユーザーが wp
になっているのは、WordPress へのファイルのアップロードで何も指定していないとパーミッションの問題で弾かれるので、WordPress のファイルを置いているユーザーを指定しています。
参考
- http://blog.kazuhooku.com/2015/12/using-h2o-with-lets-encrypt.html
- http://blog.kazuhooku.com/2015/06/h2ophpmodrewrite.html
- https://letsencrypt.readthedocs.org/en/latest/using.html