With HTTP/3 On the Horizon, Have You Upgraded to HTTP/2?

HTTP protocol.Shutterstock / Robert Avgustin

HTTP / 3 is the next version of the pass, currently in development. But 60% of the web still hasn’t been upgraded to HTTP / 2, which has been out since 2012 and has wide support. Here’s how to activate it in Nginx and Apache.

What does HTTP / 2 do?

If you’re not on HTTP / 2, you’re probably using HTTP / 1.1, which was released in 1999 when web pages were just one HTML file. Web pages these days make multiple requests for images, CSS, and JS, and while you should try to reduce the additional requests as much as possible, it is not possible to bring your technology back to 1999.

HTTP / 1.1 has a problem, however, in that it can only transfer one stream of data per connection. This means that each file is downloaded sequentially, regardless of the user’s internet speed, which can be a major slowdown, especially on large sites with many files.

HTTP / 2 corrects this problem by allowing multiple requests to be downloaded in parallel over the same TCP connection, as well as adding other features, such as header compression and the ability to push files directly to them. clients.

HTTP / 3 will be coming out soon and rebuilding the transport layer to run on UDP rather than TCP, over a new protocol called QUIC. It is in its early stages, but HTTP / 2 is already widely adopted, powering 40% of the Internet. You can already activate it if you haven’t already.

Enabling HTTP / 2 in Nginx and Apache

Support for HTTP / 2 has been built into Nginx and Apache for years now, but it’s not enabled by default, so you have to enable it manually.

One caveat of HTTP / 2 is that you must serve HTTP / 2 over a secure TLS connection, which means you must have an SSL certificate installed and configured, and force the use of HTTPS everywhere. This is not a problem though, as you should already be doing it. If you haven’t already, you can read our guide at implementation of a free LetsEncrypt certificate.

Nginx configuration

For Nginx, verify that you are on version 1.9.5 or higher by running:

sudo nginx -v

You probably are unless your server is horribly outdated; if so, update your packages:

sudo apt-get update && sudo apt-get update

Next, open your nginx site config file in your favorite text editor. It is probably located under / etc / nginx / sites-available /, under your domain name, or under “default”. Change the lines that listen on port 443 to include the http2 directive:

listen 443 ssl http2 default_server;
Listen [::]: 443 ssl http2 default_server;

You can check the syntax with:

sudo nginx -t

And restart nginx with:

sudo systemctl restart nginx

After that you should be good to go.

Apache configuration

You will need to activate the http2 module:

sudo a2enmod http2

Next, inside your virtual host definition, add the Protocols directive:

Protocols h2 http / 1.1

h2 is HTTP / 2 and HTTP / 1.1 is used as a fallback for older browsers.

Restart Apache with:

sudo systemctl restart apache2

And the changes should be saved.

Verification of changes

To check if your site is now actually using the HTTP / 2 protocol, open Chrome DevTools by right-clicking anywhere and selecting “Inspect”. Go to the “Network” tab and right click on the header of the information list to activate “Protocol”:

This will display the protocol for each request made. h2 is what you are looking for:

Look for h2.

Don’t worry if some external resources are still being served over HTTP / 1.1. You will still get the speed benefits of HTTP / 2, as requests to other servers are made through a separate connection. In the above output of howtogeek.com, some scripts for the Disqus commenting system are still served over HTTP / 1.1, which isn’t great of them, but there’s not much you can do about it. On the other hand, Google is already distributing its fonts through QUIC, if you have enabled the flag in Chrome.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.