At the beginning of 2015, it was approved the HTTP/2 protocol, the new version of the major web’s communication protocol. By the end of that year, it had already been implemented on the main search engines. You can find detailed information on its official site and a sample of this new version’s strong points here.

Today, we would like to explain how to implement the HTTP/2 protocol on your favourite web servers (we will focus on Apache and Nginx, actually).

Before getting started, you need to know that HTTP/2 is based on the spdy protocol. Therefore, it will be necessary to remove any reference to spdy from your configuration files that might exist in order to avoid redundancies. Moreover, browsers don’t support HTTP/2 encrypted, so you will need a SSL certificate for your domain – if you don’t have one yet.

Once the configuration is complete, you can use the HTTP/2 and SPDY indicator plug-in available for Chrome and Firefox to verify whether everything is working.

Apache

HTTP/2 protocol is supported by Apache since its 2.4.17 version, its first version with mod_http2.

Configuration

mod_http2 includes the new Protocols directive, which can be used overall or over specific vhost files.


# https
Protocols h2 http/1.1
...
# http, although most search engines will ignore it and will serve http/1.1
Protocols h2c http/1.1

Nginx

In September 2015, Nginx released the implementation of HTTP/2, which was committed to the open source repo and is officially available since its 1.9.5 version. It is recommended to check which version is being used before moving on. (nginx -V)

Configuration

Configuration simply consists in adding the http2 parameter to all listen directives in the server block.


server {
listen 443 ssl http2;
ssl_certificate domain.crt;
ssl_certificate_key domain.key;
...
}

Here you can find the NGINX 1.9.5 release official announcement, as well as additional interesting links about HTTP2.