Setup HTTP2 Support for Apache2

After a 15-year wait since HTTP/1.1 the next major version of HTTP was finally published.

HTTP/2 (originally named HTTP/2.0) is the second major version of the HTTP network protocol used by the World Wide Web. It is based on SPDY. HTTP/2 was developed by the Hypertext Transfer Protocol working group (httpbis, where bis means ?second?) of the Internet Engineering Task Force. HTTP/2 is the first new version of HTTP since HTTP 1.1, which was standardized in RFC 2068 in 1997

HTTP/2 maintains heigh-level compatibility with HTTP/1.1 and decreases latency to improve page load speed in web browsers. In addition, most commonly used web server support it friendly and also it’s easy to configure, so it’s a nice choice to upgrade the your site’s protocol from HTTP/1.1 to HTTP/2.

Essential Prerequisites

  • Apache 2.4.17, the first version of Apache2 with mod_http2 build in(mod_http2 is the renamed mod_h2 module).

So, if you have an Apache2 with a version under minimum requirement installed, you have to upgrade it first. In general, it is easy and friendly to upgrade apache2 to a newer or latest version on most popular OS.

Configure

  • In short, HTTP/2 protocol does not require SSL, add the following lines in your sites configurations.
1
2
3
4
5
6
7
8
# for a http server
# default http virtual host: /etc/apache2/sites-enabled/000-default.conf
Protocols h2 http/1.1
# for a https server
# default https virtual host: /etc/apache2/sites-enabled/000-default-ssl.conf
Protocols h2c http/1.1

Restart or reload your web server to make the configuration active.

Test

There are thousands of methods to test whether your sites are using HTTP/2.

  1. Check response header in Developer Tools of Google Chrome web browser.

Chrome web browser supports a powerful tools for web developer, you can check network response header in “Network” tab, and if your site are compatible with HTTP/2, you can find HTTP/2 after http version label.

  1. Request for header with cURL
1
2
3
4
5
6
7
8
9
10
curl -I --http2 https://arithxu.com
# it indicates that your curl does not support HTTP/2 protocol if it outputs : curl: (1) Unsupported protocol
# on OS X, brew supports a simple way to enable curl with HTTP/2 compatible
brew reinstall curl --with-openssl --with-nghttp2
# link the formula to replace the system cURL
brew link curl --force
# then reload the shell

cURL can only request head with -I option to reduce verbose information. In the graph below, HTTP/2 version is clearly showed in the second line in the output.

My helpful screenshot