Enabled http2 but still serving over http1.1

6,646

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.

Share:
6,646

Related videos on Youtube

JacobTheDev
Author by

JacobTheDev

Updated on September 18, 2022

Comments

  • JacobTheDev
    JacobTheDev over 1 year

    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
    
    • Doug Smythies
      Doug Smythies almost 7 years
      Do you for sure that the requester is asking for HTTP/2.? ? It is the requester that determines what the reply protocol will be (I think).
    • JacobTheDev
      JacobTheDev almost 7 years
      How would I check that?
    • Doug Smythies
      Doug Smythies almost 7 years
      Use wireshark to capture the raw packets. It will decode them and in the Hypertext Transfer Protocol section of the "GET" request there should be a "Request Version" field.
    • JacobTheDev
      JacobTheDev almost 7 years
      Installed and ran wireshark, not seeing anything that looks right... I did update my original post with the HTTP headers I get with curl if that helps
    • Tim
      Tim almost 7 years
      I got curl: (1) Unsupported protocol
  • JacobTheDev
    JacobTheDev almost 7 years
    I've already used the first method (adding the ppa:ondrej/http2 repository), enabled the mod, and restarted apache, which is why I'm confused about why this won't work. I'll try to go through the alternate method list and report back.
  • JacobTheDev
    JacobTheDev almost 7 years
    At the step where I run ./debian/rules binary I get the following error: "debian/rules:69: recipe for target 'binary' failed"
  • Peshmerge
    Peshmerge over 6 years
    I have the same issue until I have enabled sudo a2enmod mpm_event and disabled sudo a2dismod mpm_prefork