Setting up NGINX with HTTP/2 support

Introduction

HTTP/2 was published in May 2015. The advantage of HTTP/2 is its high transfer speed for content-rich websites. Most probably your website serves tons of CSS, JS and images, so why not using HTTP/2?

Main features of HTTP/2

  • All requests are downloaded in parallel without forming a queue.
  • HTTP headers are compressed.
  • Pages are fetched as a binary, not as a text file, which is more efficient.

Prerequisites

  1. NGINX 1.9.5 and later.
  2. A valid SSL certificate.

NGINX has been supporting HTTP/2 since version 1.9.5, so let's ensure we're up-to-date:

$ nginx -v
nginx version: nginx/1.10.1  

Configuration

We will be using the NGINX config file from one of the previous posts about configuring NGINX for SSL.

That will be a no-brainer sort of change. We only need to replace two following lines:

listen 443;  
listen [::]:443;  

with:

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

Next, we should restart the server.

Let's test to ensure that our content is really served via HTTP/2.

That's it, we've got a lightning-fast HTTP/2 website. Welcome to 2017!

Michael Samoylov

Python, JavaScript and Swift Expert with 12+ years of experience.

Vilnius, Lithuania https://monmar.tech

Subscribe to Michael Samoylov

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!