How to Enable HTTP/2.0 in NGINX

HTTP/2 (HTTP/2.0) is the major upgrade over HTTP/1 protocol. HTTP/2 protocol is based on SPDY (generally known as speedy). Some of the key improvements of HTTP/2 are:
  • Server push: Server will pro-actively sent components to clients, So clients doesn’t need to wait for sending requests to server.
  • Multiplexing: Reducing number of active connection by bundling multiple HTTP requests from client and sent to server.
  • Encryption: efficiently use to encryption with TLS protocol in HTTP/2 over HTTP/1.1.
  • HTTP header compression: Compressed headers will reduce the overhead of additional requests to web server.
Enable HTTP2.0 in NGINX
This article will help you to enable HTTP/2.0 in NGINX web server on CentOS / Red Hat/ Debian and Ubuntu systems.

Install NGINX

HTTP/2 protocol supported over nginx version >=1.9.5. So make sure that your nginx version is supporting HTTP/2 protocol or not. If you have not installed Nginx or older version use one of following method to install or upgrade it based on your operating system.

For CentOS / RedHat Users

First create a yum repository configuration file /etc/yum.repos.d/nginx.repo and add the following content in that file.
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 
and use the following command to install it.
# yum install nginx 

For Ubuntu Users

Use the following commands to add PPA for installing latest Nginx version on your Ubuntu system. This PPA has nginx version which supports HTTP/2 protocol.
$ echo "deb http://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx" >> /etc/apt/sources.list $ echo "deb-src http://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx"  >> /etc/apt/sources.list 
and use the following commands to install it.
$ curl http://nginx.org/keys/nginx_signing.key | apt-key add - $ sudo apt-get update $ sudo apt-get install nginx 

For Debian Users

Use the following commands to add PPA for installing latest Nginx version on your Debian system. This PPA has nginx version which supports HTTP/2 protocol.
$ echo "deb http://nginx.org/packages/mainline/debian/ `lsb_release -cs` nginx" >> /etc/apt/sources.list $ echo "deb-src http://nginx.org/packages/mainline/debian/ `lsb_release -cs` nginx"  >> /etc/apt/sources.list 
and use the following commands to install it.
$ curl http://nginx.org/keys/nginx_signing.key | apt-key add - $ sudo apt-get update $ sudo apt-get install nginx 

Verify NGINX Version

After successful installation of Nginx version on your system, make sure you have Nginx >= 1.9.5. Earlier version does not supports HTTP/2 protocol.
# nginx -v  nginx version: nginx/1.9.7 

Enable HTTP/2 in NGINX

HTTP/2 protocol requires SSL/TLS virtual hosts. You can’t use HTTP/2 protocol without SSL/TLS enabled websites. Now edit your website VirtualHost and add http2 keyword in listen section.
 server {   listen        443 ssl http2;   server_name   exmple.com;    location / {       root   /var/www/example.com;       index  index.html index.htm;   }    ssl on;   ssl_certificate  /etc/nginx/ssl/example.com.crt;   ssl_certificate_key   /etc/nginx/ssl/example.com.key;  } 

Verify HTTP/2.0

Use following online tool for testing HTTP/2 support on your website.
https://tools.keycdn.com/http2-test

Thanks for Visit Here

Comments