Skip to content

Instantly share code, notes, and snippets.

@hollodotme
Created April 9, 2016 17:07
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save hollodotme/615a36af995449751ad1f1db57a4d285 to your computer and use it in GitHub Desktop.
Save hollodotme/615a36af995449751ad1f1db57a4d285 to your computer and use it in GitHub Desktop.
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 http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx

Add nginx signing key:

wget -q -O- http://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Update package cache:

sudo apt-get update

Install new nginx

sudo apt-get install nginx

Configs

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

Done.

@huangjunque
Copy link

很有用的样子

@silpol
Copy link

silpol commented Feb 22, 2017

@ashutoshsaxena2017
Copy link

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

@kevallakhani
Copy link

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

@Lapicher
Copy link

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.

@alexroyce315
Copy link

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