Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install nginx with http2 support on ubuntu 14.04 LTS (Trusty)

How to install nginx (>= 1.9.5) with http2 support on Ubuntu 14.04 LTS (Trusty)

IMPORTANT: Backup your nginx site configs (usually under /etc/nginx/sites-available)!

Remove old nginx

Remove old nginx incl. nginx-common:

apt-get autoremove --purge nginx nginx-common

Add sources list for new nginx

Create /etc/apt/sources.list.d/nginx.list with content:

deb trusty nginx
deb-src trusty nginx

Add nginx signing key:

wget -q -O- | sudo apt-key add -

Update package cache:

sudo apt-get update

Install new nginx

sudo apt-get install nginx


Fix /etc/nginx/nginx.conf: and add this to the end of the http section:

  • Set user to www-data
  • Set worker_processes to 4
  • Set tcp_nopush to on
  • Set tcp_nodelay to on
  • Set types_hash_max_size to 2048
  • Set server_tokens to off
  • Set gzip to on
  • Set gzip_disable to "msie6"
  • Add include /etc/nginx/sites-enabled/*;

Remove /etc/nginx/conf.d/default.conf

sudo rm -rf /etc/nginx/conf.d/default.conf

Fix /etc/nginx/fastcgi_params:

  • Add fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Add sites-* folders:

sudo mkdir /etc/nginx/sites-available /etc/nginx/sites-enabled

Add your previously backuped site configs and enable them by symlinking in /etc/nginx/sites-enabled.

Enable http2

Add to your https hosts congig:

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

Restart nginx:

sudo service nginx restart



This comment has been minimized.

Copy link

huangjunque commented Feb 21, 2017



This comment has been minimized.


This comment has been minimized.

Copy link

ashutoshsaxena2017 commented Aug 18, 2017

On my ubuntu 14.04 its showing 1.13.4 version installed after running above script


This comment has been minimized.

Copy link

kevallakhani commented Jan 23, 2019

Does this still work? I upgraded nginx to 1.12.2 on ubuntu 14 but still cant the protocol being used as http2.


This comment has been minimized.

Copy link

Lapicher commented Feb 21, 2019

Thank you so much!!!, the directive "stream" works with the ngx_stream_core_module module that is available since version 1.9.0. this update helps me.


This comment has been minimized.

Copy link

alexroyce315 commented May 16, 2019

It dose not work.

nginx -V

nginx version: nginx/1.15.12
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled

You can try this... Click Here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.