2015-02-23

How to install h2o: HTTP/2 Web Server

As we already know, HTTP/2 finalized 2 weeks ago, it's a binary protocol based on SPDY, with HPACK compression. Some server benchmark has been posted, and some web server and client libraries has been supporting those specs, see the FAQ here. One of the most popular HTTP/2 is h2o that we could install in ArchLinux using this command (hipster detected):

yaourt --needed --noconfirm -S --force libuv h2o-git

You can use this configuration if you want standalone web server (h2o requires TLS encrpytion for HTTP/2):

listen: 
  port: 3030
  ssl:
    certificate-file: /path/to/localhost.crt
    key-file: /path/to/localhost.key
http2-max-concurrent-requests-per-connection: 1024
num-threads: 1
hosts:
  127.0.0.1:
    paths:
      /:
        file.dir: /path/to/htdocs
        file.dirlisting: ON

Or if you want to use it as reverse proxy (just like normal NginX use case):

listen:
  port: 3040

  ssl:
    certificate-file: /path/to/server.crt
    key-file: /path/to/server.key
http2-max-concurrent-requests-per-connection: 1024
num-threads: 1
hosts:
  localhost:
    paths:
      /:
        proxy.reverse.url: http://127.0.0.1:3030
        proxy.keepalive: ON

The h2o server seems not allowing HTTP/2 to be used when started without SSL. If you don't have any SSL certificate yet, just use this command to generate self-signed certificate:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt

To start the h2o program, just write those configuration (don't forget to change the certificate-file, key-file, and file.dir to use the correct path) to a file named h2o.conf, then just type:

$ h2o
[OCSP Stapling] disabled for certificate file:/tmp/localhost.crt
[INFO] raised RLIMIT_NOFILE to 65536
h2o server (pid:11108) is ready to serve requests
[OCSP Stapling] disabled for certificate file:/tmp/localhost.crt   

To enable browser support for this protocol, you can enable the SPDY/4 flag on chrome://flags (type it on your Chrome's address bar) or search for http2 flags inside about:config at Firefox's address bar.



To check which websites already using SPDY, you can visit chrome://net-internals/#spdy. You can also use this Chrome extension or this Firefox plugin to check is it SPDY enabled site (see the lightning sign after installing ). 


To check public website for SPDY or HTTP/2 support (labeled as h2-xx, where xx is the spec revision), you can use spdycheck.org. Another way to check a site is using HTTP/2 without browser is using latest httpie-http2 or nghttp2-git, that you can install using these commands:

# httpie
yaourt --needed --noconfirm -S --force python-pip
sudo pip3 install -U httpie httpie-http2

# nghttp2
yaourt --needed --noconfirm -S --force cunit libev
yaourt --needed --noconfirm -S --force nghttp2-git

then just execute one of these commands:

# httpie
http https://nghttp2.org/httpbin/get

# nghttp2
nghttp2 -nva https://localhost:3030

The httpie command, always failed when using self-signed certificate (even when --verify=no enabled). For nghttp2, when there are line containing The negotiated protocol: h2, it shows HTTP/2 protocol being used. 




5 comments :

  1. Thanks for this. I am trying to install h2o with ssl. This helped me.

    ReplyDelete
  2. Hi All,
    does anyone knows, how to make the h20 working with php?
    I can't open *.php-files with the example configuration file.
    On Google I didn't found any comments.

    Thanks in advance for any helpful hint.

    ReplyDelete
  3. I don't think it can be done easily for now, because:
    1. no fastcgi support, yet https://github.com/h2o/h2o/issues/200
    2. no one make the php module, yet

    the workaround for now would be using h2o as reverse-proxy to another web server that support php (or preferably just use hhvm built-in web server instead of another web server+php)

    ReplyDelete
  4. bandarq
    Capsa Susun
    KlikQQ
    Prediksi Bola


    bandarq
    Capsa Susun
    KlikQQ
    Prediksi Bola
    #206.189.46.152/bandarq/ #206.189.46.152/klikqq/ #klikqq #klikkiu #bandarq #marinabet365.com

    ReplyDelete

THINK: is it True? is it Helpful? is it Inspiring? is it Necessary? is it Kind?