قالب وردپرس درنا توس
Home / Tips and Tricks / Have you upgraded to HTTP / 2 on the horizon? – CloudSavvy IT

Have you upgraded to HTTP / 2 on the horizon? – CloudSavvy IT



HTTP protocol.
Shutterstock / Robert Avgustin

HTTP / 3 is the next version of col, which is currently being developed. But 60% of the web has still not upgraded to HTTP / 2 yet, which has been out since 201

2 and has widespread support. How to enable it in Nginx and Apache.

What does HTTP / 2 do?

If you are not into HTTP / 2, you are probably using HTTP / 1.1, which was released in 1999 when web pages were just a single HTML file. Nowadays, web pages make several requests for images, CSS and JS, and although you should try to cut as much as possible on extra requests, it is not possible to set your technology back to 1999.

However, HTTP / 1.1 has a problem, as it can only transmit one data stream per connection. This means that each file is downloaded in turn, regardless of the user’s internet speed, which can be a major downturn, especially on large websites with many files.

HTTP / 2 addresses this by allowing multiple requests to be downloaded in parallel over the same TCP connection, along with adding other features, such as master compression and the ability to drive files directly to clients.

HTTP / 3 will soon be released and rebuild the transport layer to work over UDP rather than TCP, on a new protocol called QUIC. It is in its early stages, but HTTP / 2 has already been widely used and drives 40% of the internet. You can already activate it if you have not already done so.

Enable HTTP / 2 in Nginx and Apache

HTTP / 2 support has been baked in Nginx and Apache for several years now, but it is not on by default, so you need to enable it manually.

An alert 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. However, this is not a problem, as you should already be doing this. If you have not yet done so, you can read our guide to setting up a free LetsEncrypt certificate.

Nginx configuration

For Nginx, verify that you are in version 1.9.5 or later by running:

sudo nginx -v

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

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

Then open the configuration file for your nginx Web site in your favorite text editor. It’s probably below /etc/nginx/sites-available/, either under your domain name or “default.” Change the lines that listen to port 443 to include http2 directive:

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

You can check syntax with:

sudo nginx -t

And restart nginx with:

sudo systemctl restart nginx

After that, you should be ready.

Apache configuration

You must activate http2 module:

sudo a2enmod http2

Then add to your Virtual Host definition Protocols directive:


  Protocols h2 http/1.1

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

Restart Apache with:

sudo systemctl restart apache2

And the changes should be saved.

Verify the changes

To check if your site is 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 heading in the information list to activate “Protocol”:

Enable

This shows the protocol for each request. h2 is what you are looking for:

Look for h2.

Do not worry if some external resources are still served via HTTP / 1.1. You will still see the speed benefits of HTTP / 2, as requests to other servers are made via a separate connection. In the above output from howtogeek.com, some scripts for the Disqus commenting system are still served via HTTP / 1.1, which is not good on their part, but there is not much you can do about it. On the other hand, Google actually serves its fonts over QUIC already if you have enabled the flag in Chrome.


Source link