Enable http2 in apache

July 17, 2019 204 views
Apache Ubuntu 18.04

Hi, I tried to enable http2 with apache2 but I couldn’t. I did this:

  • I activated http2 with this: sudo a2enmod http2
  • I added this line in my virtual host with 443 port: Protocols h2 http/1.1.

I have a ubuntu server 18.04.2 and apache 2.4.29, also i use letsencrypt for the site.

I need to do something else?

Thanks

1 Answer

Hello,

That should be pretty much it.

You can now use your browser to check if the resources are actually going through http2. You can do that with the browsers developer tool, then go to the networking tab and try accessing your site, there you should see the protocol that is being used.

Note that the Protocol column might not be there, so you need to enable it, just right click on any of the other columns and choose tick the Protocol from the drop down.

Let me know how it goes!
Bobby

  • Hi, thanks, I checked this but not work the http2, I think that I need to do someting else.

    • That is pretty much it, I have the same setup for my website actually. You can check it here:

      https://bobbyiliev.com

      One thing that I could suggest is adding the Protocols h2 http/1.1 line in your Vhost for port 80 as well. Also did you restart apache after the changes?

      Regards,
      Bobby

      • Hi, yes I rebooted apache and server. This is my virtual host configuration (80 and 443):

        <VirtualHost *:80>
            ServerAdmin abc2039@gmail.com
            ServerName abc.com
            ServerAlias www.abc.com
            DocumentRoot /var/www/abc.com/html
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =abc.com [OR]
        RewriteCond %{SERVER_NAME} =www.abc.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
        <Directory /var/www/abc.com/>
            AllowOverride All
        </Directory>
        
        Protocols h2 http/1.1
        </VirtualHost>
        
        <IfModule mod_ssl.c>
        <VirtualHost *:443>
            ServerAdmin xxxx9@gmail.com
            ServerName abc.com
            ServerAlias www.abc.com
            DocumentRoot /var/www/abc.com/html
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
        
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/abc.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/abc.com/privkey.pem
        Protocols h2 http/1.1
        </VirtualHost>
        </IfModule>
        

        And in apache2.conf I added “Protocols h2 h2c http/1.1”

Have another answer? Share your knowledge.