How to Add HTTP2 Support to Nginx on Debian

Modified on: Mon, Jul 25, 2016 at 11:50 am EST

Introduction

HTTP2 is the new/updated version of HTTP which focuses mainly on performance, specifically, end-user perceived latency, network and server resource usage. One major goal is to allow the use of a single connection from browsers to a Web site.

Requirements

  • Debian 7 or 8
  • Nginx 1.9.5 or newer

Installation

If you already have the latest version of Nginx installed on your server, you can skip to the Configuration part of this tutorial. Otherwise, please follow the steps below to install the latest version of Nginx.

Add the Nginx APT Repository by adding the following to lines to. your /etc/apt/sources.list file:

deb http://nginx.org/packages/mainline/debian/ wheezy nginx
deb-src http://nginx.org/packages/mainline/debian/ wheezy nginx

Note: Replace wheezy with jessie if applicable.

Next, we install Nginx:

apt-get update
apt-get install nginx

Please run the following command to confirm that you are running Nginx 1.9.5 (or newer):

nginx -v

Output: nginx version: nginx/1.9.5

Configuration

To enable HTTP2 for your SSL Vhosts, change the listen line in /etc/nginx/conf.d/default.conf to look like the example below:

listen 443 ssl http2;

If you wish to force redirect all your non-SSL (HTTP) websites to HTTPS, add the follow server block at the top of of your Nginx configuration file:

server {
 listen         80;
 listen         [::]:80;
 server_name    _;
 return 301 https://$host$request_uri;
}

We can now restart Nginx and visit our website at https://SERVER_IP/:

service nginx restart

This concludes our tutorial, thank you for reading.

Get started in the SSD Cloud !