How To Set Up Apache with HTTP/2 Support on Debian 9

How To Set Up Apache with HTTP/2 Support on Debian 9

We will show you how to set up Apache with HTTP/2 support on Debian 9. HTTP/2 is a major revision of the HTTP network protocol. It is derived from the experimental SPDY protocol developed by Google. The primary goal of HTTP/2 is to reduce the latency, minimize the protocol overhead and add support for request prioritization. This makes the web applications to load much faster.High level syntax like status codes, methods, headers fields, URIs etc. are the same as the earlier version of HTTP except there is a difference on how the data is framed and transported between the client and the server.

The Apache web server version that is available in the Debian 9 repositories has HTTP/2 support out of the box. Basically, when you install Apache web server on your Debian 9 VPS, you have the HTTP/2 module available to use. There is no need to install Apache from source like before when the earlier versions of HTTP/2 were not ready for production.

Enable HTTP/2 module in Apache

The HTTP/2 protocol is implemented by its own Apache module named mod_http2. To be able to use HTTP/2 in Apache you need to make sure the module is enabled. Connect to your server via SSH and run the following command to enable the HTTP/2 module in Apache:

a2enmod http2

You will see the following output:

# a2enmod http2
Enabling module http2.
To activate the new configuration, you need to run:
  systemctl restart apache2

The output tells you that the module is enabled in Apache and that you need to restart the Apache service for the changes to take effect. To restart the Apache service, run the following command:

systemctl restart apache2

To make sure the module is enabled and ready to use make check the following file:

cat /etc/apache2/mods-enabled/http2.load

and make sure the following line is there:

LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so

Or, simply use the following command and it will show you whether the module is enabled or not:

apache2ctl -M | grep http2

If it is enabled, the output will be similar to the following:

# apache2ctl -M | grep http2
 http2_module (shared)

Enable HTTP/2 in your Apache virtual host

Most browsers will speak HTTP/2 only via HTTPS which means your web server must have support for HTTPS and you need to have a valid SSL certificate installed. Otherwise, HTTP/2 will not work. To enable global support for HTTP/2 in Apache edit the default SSL virtual host configuration file using a text editor of your choice. We are using nano in our example:

nano /etc/apache2/sites-enabled/default-ssl.conf

and add the following line after the opening <VirtualHost *:443> tag:

Protocols h2 h2c http/1.1

If you want to enable HTTP/2 for specific domain/website, add that line in the virtual host for that specific website. The virtual host for your domain should look like the following one:

<VirtualHost *:443>
    Protocols h2 h2c http/1.1
    ServerAdmin [email protected]
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/html/example.com

    SSLEngine On
    SSLCertificateFile /etc/ssl/certs/example.com.crt
    SSLCertificateKeyFile /etc/ssl/private/example.com.key
    SSLCACertificateFile /etc/ssl/certs/ca-certificates.crt

    <Directory /var/www/html/example.com/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
     </Directory>

    ErrorLog /var/www/html/example.com/log/error.log
    CustomLog /var/www/html/example.com/log/access.log combined
</VirtualHost>

Once you add the line related to protocols in your Apache virtual host file, you have to restart Apache again for the changes to take effect.

Please note, the order of protocols is relevant so the first one is the most preferred protocol when the client offers multiple choices. Here, h2 means HTTP/2 will be used over TLS (protocol negotiation via ALPN), while h2c means HTTP/s will be used over TCP. http/1.1 means that if the client doesn’t accept HTTP/2 then the request will be served over HTTP/1.1.

Verify that HTTP/2 support is enabled in Apache

To check whether HTTP/2 is successfully enabled in Apache you can use RoseHosting’s online HTTP/2 checker tool or any other similar tool available online.


Of course, you don’t have to set up Apache with HTTP/2 support on Debian 9, if you use one of our Linux Server Management Services, in which case you can simply ask our expert Linux admins to set up Apache with HTTP/2 support on Debian 9 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to set up Apache with HTTP/2 support on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

3 thoughts on “How To Set Up Apache with HTTP/2 Support on Debian 9

  1. Pingback: bahis siteleri

Leave a Reply

Your email address will not be published. Required fields are marked *