Almost two years ago I switched from HTTP/1.1 to HTTP/2 with Apache2. Here is what I did. If you want to know more about HTTP/2, read HTTP/1.1 vs HTTP/2: What’s the Difference?.
Setup HTTPS
As most of the browsers supports HTTP/2 over TLS only, we first need to setup HTTPS. For instance, Firefox claims:
Firefox will only be implementing HTTP/2 over TLS - and so far that means for https:// schemed URLs (…).
Therefore, we’ll use Let’s Encrypt, which is a free, automated and open certificate authority and Certbot a free, open source software tool for automatically using Let’s Encrypt certificates on manually-administrated websites to enable HTTPS.
First, install Certbot:
To obtain a SSL certificate, launch:
Just let you guide, and at the question Redirect non secure connection to secure connection?, answer Yes.
Maybe you have a firewall on your server that blocks SSL connexions. In my case, I had to configure my ferm
firewall to open the 443 port:
And that’s it, it works out of the box! Cerbot updated the Apache configuration and provides a cron task to renew the certificate automatically before it expires (check the file /etc/cron.d/certbot
).
For a more detailed guide about using Certbot with Apache, refer to How To Secure Apache with Let’s Encrypt on Debian 9.
Setup HTTP/2
OK, now we have HTTPS on our domain, we can set up HTTP/2.
First you need to enable the http2
mode for Apache:
Then you need to configure your virtual host:
Reload Apache:
Yeah, it should work! Let’s check:
Houston, we’ve got a problem… The response tells us we are still using HTTP/1.1 🤔
Setup Apache2 with mpm-event
The answer is in the logs:
HTTP/2 is not “supported” by MPM Prefork. I chose to use Event instead:
Check again if it works 🤞
Perfect!
I didn’t try yet to tweak it further, thanks to the H2PushResource directive for instance. That’s enough for that blog.