Enabled http2 but still serving over http1.1

To enabled HTTP/2 on my 16.04 server, I followed this guide as recommended by Google, but for some reason my site is still being served over HTTP/1.1. I've checked and double checked that everything is correct, restarted the service (and the server!) several times, all to no avail.

  • http2 mod is enabled in apache2.
  • Protocols h2 h2c http/1.1 is added to my site configuration file (and just tested in my apache.conf)
  • I have restarted the service and the server

Am I missing something?

EDIT:

Just ran curl -I -k --http2 https://framework.jacob.rocks/ and received the following...

HTTP/1.1 200 OK
Date: Thu, 20 Jul 2017 17:12:52 GMT
Server: Apache/2.4.27 (Ubuntu)
Upgrade: h2,h2c
Connection: Upgrade
Link: <https://framework.jacob.rocks/wp-json/>; rel="https://api.w.org/"
Link: <https://framework.jacob.rocks/>; rel=shortlink
X-TEC-API-VERSION: v1
X-TEC-API-ROOT: https://framework.jacob.rocks/wp-json/tribe/events/v1/
X-TEC-API-ORIGIN: https://framework.jacob.rocks
Content-Type: text/html; charset=UTF-8

Solution 1:

Figured this out, apparently it was just an issue with mpm_prefork module that doesn't support HTTP/2 starting from Apache 2.4.27. I followed this guide and it now works!

Solution 2:

Apache2 is not compiled with http2 support by default on ubuntu 16.04.

So you either have to install a precompiled version of it, for example doing this :

sudo add-apt-repository ppa:ondrej/apache2
sudo apt-get update
sudo apt-get dist-upgrade

Or doing it by yourself with the following method :

Check you have those lines in /etc/apt/sources.list :

deb-src http://archive.ubuntu.com/ubuntu/ xenial main universe restricted multiverse
deb-src http://security.ubuntu.com/ubuntu xenial-security main universe restricted multiverse
deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates main universe restricted multiverse

If not, add them with :

sudo echo 'deb-src http://archive.ubuntu.com/ubuntu/ xenial main universe restricted multiverse
deb-src http://security.ubuntu.com/ubuntu xenial-security main universe restricted multiverse
deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates main universe restricted multiverse' >> /etc/apt/sources.list

Then install some needed packages (libnghttp2-dev is necessary to bring http2 support) :

sudo apt-get install curl devscripts build-essential libnghttp2-dev 
sudo apt-get build-dep apache2
sudo apt-get source apache2

Then compile :

cd apache-2.4.18
sudo su
./debian/rules binary

At this stage, you could install the generated deb, but they might be overwritten by a security update later, so we'll just copy the module http2 which has been generated and create a file to be able to enable it :

cp debian/apache2-bin/usr/lib/apache2/modules/mod_http2.so /usr/lib/apache2/modules/

Then create the file http2.load to load the module.

echo 'LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so
    <IfModule http2_module>
    LogLevel http2:info
    </IfModule>' > /etc/apache2/mods-available/http2.load

Then enable the module

a2enmod http2

Then restart apache

service apache2 restart

Now you should be good to go.