{"id":9498,"date":"2021-08-23T14:38:57","date_gmt":"2021-08-23T14:38:57","guid":{"rendered":"https:\/\/linuxways.net\/?p=9498"},"modified":"2021-08-23T14:38:57","modified_gmt":"2021-08-23T14:38:57","slug":"how-to-configure-http-2-in-nginx-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-configure-http-2-in-nginx-on-ubuntu-20-04\/","title":{"rendered":"How to Configure HTTP\/2 in Nginx on Ubuntu 20.04"},"content":{"rendered":"<p>The HTTP\/2 protocol is an improvement of its predecessor HTTP\/1.1. It provides numerous benefits and improvements such as faster page loading speeds and increased security. If you are running Nginx on HTTP\/1.1, then you should consider migrating to HTTP\/2.<\/p>\n<p>In this guide, we will explore How to enable HTTP\/2 on Nginx on Ubuntu 20.04<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>As you get prepared to configure HTTP\/2 on your Nginx webserver, ensure you have the following:<\/p>\n<p>Nginx web server that is v 1.9.5 or greater. We have a guide on <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-nginx-on-ubuntu-20-04\/\">how to install Nginx on Ubuntu 20.04<\/a>. To check the version of Nginx that is installed, simply run the command<strong>:<\/strong><\/p>\n<pre><strong>$ nginx -V<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"493\" height=\"93\" class=\"wp-image-9499\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-421.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-421.png 493w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-421-300x57.png 300w\" sizes=\"auto, (max-width: 493px) 100vw, 493px\" \/><\/strong><\/p>\n<p>Next, ensure that you have OpenSSL 1.0.2 or later versions. To verify the version you are running, issue the command:<\/p>\n<pre><strong>$ openssl version<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"93\" class=\"wp-image-9500\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-422.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-422.png 496w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-422-300x56.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/p>\n<p>Also, for this to work, you need to have the webserver encrypted with an SSL certificate. Here, our webserver is encrypted using the Let\u2019s Encrypt SSL certificate. Already we have this set up where our domain name is <strong>linuxtechgeek.info<\/strong> and pointed to our virtual server\u2019s IP address. Additionally, we have configured a virtual host file for the domain.<\/p>\n<p>Lastly, your server must be using TLS v 1.2 and later versions.<\/p>\n<h2><strong>Step 1: Test that your site is using HTTP\/1<\/strong><\/h2>\n<p>To get started out, we need to verify that our web server is currently using HTTP\/1.1. To achieve this, we will run the curl command shown<\/p>\n<pre><strong>$ curl -I https:\/\/domain-name<\/strong><\/pre>\n<p>In our case, this is going to be:<\/p>\n<pre><strong>$ curl -I https:\/\/linuxtechgeek.info<\/strong><\/pre>\n<p>The first line of the output clearly indicates that we are using HTTP\/1.1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"607\" height=\"207\" class=\"wp-image-9501\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-423.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-423.png 607w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-423-300x102.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/p>\n<h2><strong>Step 2: Enable HTTP\/2 by editing the virtual host file<\/strong><\/h2>\n<p>To enable HTTP\/2 we need to edit or modify the domain\u2019s virtual host file.<\/p>\n<pre><strong>$ sudo vim \/etc\/nginx\/sites-available\/linuxtechgeek.info<\/strong><\/pre>\n<p>Locate this line:<\/p>\n<pre><strong>listen 443 ssl <\/strong><\/pre>\n<p>Append the attribute <strong>http2 <\/strong> just after <strong>ssl.<\/strong><\/p>\n<p>In case you have a line that starts as follows:<\/p>\n<p><strong>listen [::]:443 ssl \u2026<\/strong><\/p>\n<p>Add the <strong>http2 <\/strong>attribute as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"302\" class=\"wp-image-9502\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-424.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-424.png 796w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-424-300x114.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-424-768x291.png 768w\" sizes=\"auto, (max-width: 796px) 100vw, 796px\" \/><\/p>\n<p>Save the changes and exit.<\/p>\n<h2><strong>Step 3: Verify if Nginx configuration is Ok<\/strong><\/h2>\n<p>Once you have exited the virtual host file, restart the Nginx webserver<\/p>\n<pre><strong>$ sudo systemctl restart nginx<\/strong><\/pre>\n<p>Next, check if the Nginx configuration is sound:<\/p>\n<pre><strong>$ sudo nginx -t<\/strong><\/pre>\n<p>From the output, the Nginx configuration is OK.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"674\" height=\"166\" class=\"wp-image-9503\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-425.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-425.png 674w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-425-300x74.png 300w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/p>\n<h2><strong>Step 4: Check if HTTP\/2 is enabled<\/strong><\/h2>\n<p>Finally, to verify if HTTP\/2 is enabled, execute:<\/p>\n<pre><strong>$ curl -I https:\/\/linuxtechgeek.info<\/strong><\/pre>\n<p>From the output, HTTP\/2 is now enabled. Perfect!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"201\" class=\"wp-image-9504\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-426.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-426.png 655w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-426-300x92.png 300w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>That was a brief guide on how to enable HTTP\/2 on the Nginx webserver on Ubuntu 20.04<\/p>","protected":false},"excerpt":{"rendered":"<p>The HTTP\/2 protocol is an improvement of its predecessor HTTP\/1.1. It provides numerous benefits and improvements such as faster page loading speeds and increased security. If you are&hellip;<\/p>","protected":false},"author":1,"featured_media":9604,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[149,100],"class_list":["post-9498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-nginx","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=9498"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9498\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/9604"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=9498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=9498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=9498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}