Nginx is a widely used web server today. The reason why it’s popular is that it is fast, consumes fewer resources, is highly scalable, supports lots of protocols, and is easy to configure. When coming to HTTP2, is a new version of Hyper Text Transfer Protocol. Before the launch of HTTP2, HTTP1.1 was the only protocol available. In the past, websites mostly consists of one HTML page along with some inlined CSS. HTTP1.1 protocol downloads one the complete page first and then moves to other pages which makes the website damn slow to load. But today websites have grown bigger and multiple pages and scripts load at the same time. This multi-download was made available HTTP2 version.
Read More:- How to Enable gzip compression for WordPress in Nginx Ubuntu?
HTTP2 solves many problems and has got many changes too, like
- Multiple pages and requests are downloaded parallelly and not in a queue.
- It offers compressed HTTP headers
- Page transfers are efficient as it works as binary and not as text file.
- Servers are allowed to push the data without users’ consent, which improves the performance to a great extent
Even if HTTP2 doesn’t require any kind of encryption, still most of the developers say they support HTTP2 for HTTPS connections only. So having a secured setup is important.
Here is how to enable HTTP2 in Nginx Ubuntu
Before making any changes, make sure you have configured your Nginx server along with SSL, and it’s running perfectly fine.
Open your vhost file located in /etc/nginx/sites-available/vhost.conf
You will find these two lines
...
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
…
Change those to
…
listen [::]:443 ssl http2 ipv6only=on;
listen 443 ssl http2;
…
Check and compile with
$ sudo nginx -t
If everything goes well, restart the Nginx server
$ sudo systemctl restart nginx
That’s it.