How to enable HTTP/2 on Apache on Centos/Redhat - mod_http2

  • Last update: Apr 3, 2024
  • Views: 93
  • Author: Admin
How to enable HTTP/2 on Apache on Centos/Redhat - mod_http2

Hello colleagues.

The HTTP/2 protocol was released in 2015 as a more advanced version of the HTTP/1.1 protocol. This protocol will allow you to greatly speed up your site and reduce the load on the Apache web server and communication channel. All this will lead to a reduction in the cost of renting capacities and even increase the position of your site in search engines, because google looks at the loading rates of your site, and if the site takes a very long time to load, then the site indicators will be low. The HTTP/2 protocol can load several page elements in parallel over a single TCP connection, and this reduces the page load delay in order to quickly return the requested content to the user.

 

The main advantages of the HTTP/2 protocol over HTTP/1.1.

  • HTTP header compression.
  • Push technologies.
  • Parallel loading of page elements.
  • A binary protocol, unlike HTTP 1.1, which is plain text.

 

HTTP/2 protocol can only be used if your Apache web server is at least version 2.2. Therefore, if your Apache version is lower than 2.2, then you first need to upgrade Apache to a compatible version. In order for you to be able to enable the HTTP/2 protocol, you need to have two modules before Apache, the first is mod_http2 and the second is mod_ssl.

 

The content of the article:

  1. Installing the mod_http2 module.
  2. Installing the mod_ssl module.
  3. Checking if HTTP/2 is enabled.
  4. Checking if the HTTP/2 module is enabled in Apache.
  5. Enable HTTP/2.
  6. Rechecking whether the HTTP/2 protocol is enabled.

 

1. Installing the mod_http2 module.

When you install Apache itself, the mod_http2 module should come as a dependency.

centos enable http2

If you don't have the  mod_http2 module, be sure to install it. To install the mod_http2 module, use the command:

$. sudo yum install mod_http2


 

2. Installing the mod_ssl module.

The mod_ssl module is needed in order to successfully use an SSL certificate for your site and your site worked not with the http protocol, but with the https protocol. If you do not have this module, then you can install it with the command:

$. sudo yum install mod_ssl

centos enable http2

If you do not plan to use an SSL certificate on your site, then you can not install mod_ssl.


 

3. Checking if HTTP/2 is enabled.

Before setting up HTTP/2, let's first make sure that HTTP/2 is not currently working for us. Command to check:

$. curl --http2 --head http://localhost | grep HTTP

centos enable http2

As you can see, now we only use the HTTP / 1.1 protocol


 

4. Checking if the HTTP/2 module is enabled in Apache.

At this point, you need to make sure that the HTTP/2 module is loaded during Apache startup. To check, use the command:

$. cat /etc/httpd/conf.modules.d/10-h2.conf

centos enable http2

As a result you should get - LoadModule http2_module modules/mod_http2.so

This means that the module is loaded during Apache startup.


 

5. Turn on HTTP/2.

Now it's the turn to enable the HTTP/2 protocol.

If you are not using virtual hosts, then you need to open the main Apache httpd.conf configuration file located along the /etc/httpd/conf path and add the line at the beginning of the file:

Protocols h2 h2c http/1.1

centos enable http2

 

Well, if you are using virtual hosts, then you need to open the configuration file of your site and add the same parameter to it.

<VirtualHost ...>
    ServerName it-inzhener.com
    Protocols h2 h2c http/1.1
</VirtualHost>

 

After save the file and be sure to restart the Apache web server.

$. service httpd restart

 

Descriptions of protocol parameters.

  • h2 - tells the Apache server to support the HTTP/2 protocol over SSL/TLS.
  • h2c - tells the Apache server to support HTTP/2 over TCP.
  • http/1.1 - tells ver to the server that if the client does not accept HTTP/2, then serve the request over the HTTP/1.1 protocol.

 

6. Recheck if the HTTP/2 protocol is enabled.

After all that we have done, now let's check, for this we will use the same command that we used in the third paragraph.

$. curl --http2 --head http://localhost | grep HTTP

centos enable http2

As you can see, as a result, we now have the HTTP/2 protocol successfully working on our site.


 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES