読者です 読者をやめる 読者になる 読者になる

How to serve Mastodon via h2o web server(Mastodonをh2oで配信する方法)

h2o is great http/2 web server(MIT license).
http/2 protocol leads very good performance with page with many files.
I love h2o server!
I will write about how to serve Mastodon via h2o.

h2oは素晴らしいhttp/2対応のwebサーバーです(MIT ライセンス)。
http/2はたくさんのファイル読み込みがあるページなどで良いパフォーマンスを発揮します。
h2oが好きだー!
h2oでMastodonを配信する方法を記述します。

environment(環境)

server: ubuntu16.04
Front web server is h2o,backend server are apache2.4 and masdon server(docker).
フロントはh2o。バックエンドはapache2.4とdockerのmastodonです

h2o ----   apache2 (domain1) port:81
    |
    ----   docker server(domain2 - mastodon) port:3000,4000

h2o config

very simple,but "//api/v1/streaming/" is little complex.why "/api/v1/streaming/" ? I think this is mastodon's problem but I solved.
とてもかんたんですね。"//api/v1/streaming/"のところがちょっときもいですけど、まぁ、なんとか。

user: www-data
hosts:
  "lovesaemi.daemon.asia":
    listen:
      port: 80
    paths:
      "/":
        redirect: "https://lovesaemi.daemon.asia"
  "lovesaemi.daemon.asia:443":
     listen:
       port: 443
       ssl:
          certificate-file: /etc/letsencrypt/live/lovesaemi.daemon.asia/fullchain.pem
          key-file: /etc/letsencrypt/live/lovesaemi.daemon.asia/privkey.pem
          cipher-suite: "EECDH+AESGCM:AES256+EECDH:AES128+EECDH"
          cipher-preference: server
          minimum-version: TLSv1.2
     paths:
       "/":
         proxy.reverse.url: http://127.0.0.1:81/
  "mastdn.lovesaemi.daemon.asia":
    listen:
      port: 80
    paths:
      "/":
        redirect: "https://mastdn.lovesaemi.daemon.asia"
  "mastdn.lovesaemi.daemon.asia:443":
     listen:
       port: 443
       ssl:
          certificate-file: /etc/letsencrypt/live/mastdn.lovesaemi.daemon.asia/fullchain.pem
          key-file: /etc/letsencrypt/live/mastdn.lovesaemi.daemon.asia/privkey.pem
          cipher-suite: "EECDH+AESGCM:AES256+EECDH:AES128+EECDH"
          cipher-preference: server
          minimum-version: TLSv1.2
     paths:
       "//api/v1/streaming/":
         proxy.websocket: ON
         proxy.preserve-host: ON
         proxy.reverse.url: http://127.0.0.1:4000/
       "/":
         proxy.preserve-host: ON
         proxy.reverse.url: http://127.0.0.1:3000/
access-log: /var/log/h2o/access-log
error-log: /var/log/h2o/error-log
pid-file: /tmp/h2o.pid

check http/2 ? http/2で動いてる?

f:id:new_pill:20170430003959p:plain
f:id:new_pill:20170430003857p:plain
OK,http/2
http/2ですね。良い感じ。

enjoy!
是非h2oを使ってみてください。