Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Enable HTTP/2.0 in Nginx - DesignLinux

Jun 17 2020
designlinux 0 Comments

HTTP/2 is the latest standard for the HTTP protocol, it is the successor of HTTP/1.1. It is becoming increasingly popular due to the benefits it brings to web developers and users in general. It provides an optimized transport for HTTP semantics by supporting all the core features of HTTP/1.1 but aims to be more efficient in multiple ways.

There are a lot of features on top of HTTP/2 that give you more possibilities to optimize a web site/application. It offers true multiplexing and concurrency, better header compression (binary encoding), better prioritization, better flow control mechanisms, and a new interaction mode called “server push” that enables a server to push responses to a client. Not to mention, HTTP/2 is based on Google’s experimental SPDY protocol.

Therefore, the primary focus of HTTP/2 is to reduce overall web page loading time, thus improving performance. It also focuses on network and server resource usage as well as security because, with HTTP/2, SSL/TLS encryption is mandatory.

In this article, you will learn how to enable Nginx with HTTP/2 support in Linux servers.

Prerequisites:

  • A working installation of NGINX version 1.9.5 or higher, built with the ngx_http_v2_module module.
  • Make sure that your site uses SSL/TLS certificate, if you don’t have one, you can obtain from Let’s Encrypt or use a self-signed certificate.

You can install NGINX or deploy it with a LEMP stack as described in the following guides:

  • How to Install Nginx on CentOS 8
  • How To Install LEMP Server on CentOS 8
  • How To Install NGINX, MySQL/MariaDB and PHP on RHEL 8
  • How to Install LEMP Stack with PhpMyAdmin in Ubuntu 20.04
  • Install Nginx with Server Blocks (Virtual Hosts) on Debian 10
  • How to Use Nginx as an HTTP Load Balancer in Linux

How to Enable HTTP/2.0 in NGINX

If you have NGINX installed, verify that it was built with the ngx_http_v2_module module by running the following command.

# strings /usr/sbin/nginx | grep _module | grep -v configure| sort | grep ngx_http_v2_module
Check Nginx HTTP/2 Module

Check Nginx HTTP/2 Module

Once you have a web site/application being served by NGINX with HTTPS configured, open your websites virtual server block (or virtual host) file for editing.

# vi /etc/nginx/conf.d/example.com.conf                    [On CentOS/RHEL]
$ sudo nano /etc/nginx/sites-available/example.com.conf    [On Ubuntu/Debian]

You can enable HTTP/2 support by simply adding the http2 parameter to all listen directives as shown in the following screenshot.

listen 443 ssl http2;

The sample server block configuration looks like below.

server {
        server_name example.com www.example.com;
        access_log  /var/log/nginx/example.com_access.log;
        error_log  /var/log/nginx/example.com_error.log;

        listen [::]:443 ssl ipv6only=on http2; # managed by Certbot
        listen 443 ssl http2; # managed by Certbot

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot    
}
Enable HTTP/2 Support in Nginx

Enable HTTP/2 Support in Nginx

Save the changes in the file and close it.

Then check the NGINX’s configuration syntax, if it’s OK, restart the Nginx service.

# nginx -t
# systemctl restart nginx

Next, open a web browser to verify if your website is being served over HTTP/2.

http://www.example.com

To access the HTTP headers, right-click on the displayed web page, select Inspect from the list of options to open the developer tools, then click the Network tab, and reload the page.

Check under Protocols to see the one your site is using (if you don’t see the Protocols header, right-click on any of the headers e.g Name, then check Protocol from the list to display it as a header).

If your site is running on HTTP/1.1, under Protocol, you will see http/1.1 as shown in the following screenshot.

Website Running on HTTP/1.1

Website Running on HTTP/1.1

If it is running on HTTP/2, under Protocol, you will see h2 as shown in the following screenshot. You may want to disable the browser cache to view the latest content being served directly from the webserver.

Website Running on HTTP/2.0

Website Running on HTTP/2.0

That’s all! For more information, see the ngx_http_v2_module module documentation. Do not hesitate to ask questions via the feedback form below.

Sharing is Caring…
Share on FacebookShare on TwitterShare on LinkedinShare on Reddit

Related

Tags: Nginx Tips

Python Modulo Operator

Prev Post

How to Install and Use PHP Composer on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 2
  • 610
  • 1,055,382

DesignLinux.com © All rights reserved

Go to mobile version