Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Last active January 7, 2021 12:58
Show Gist options
  • Save tangoabcdelta/87335bf4e6cdcbb8a6ba576bd82cdf8a to your computer and use it in GitHub Desktop.
Save tangoabcdelta/87335bf4e6cdcbb8a6ba576bd82cdf8a to your computer and use it in GitHub Desktop.
Installation Guide - nginx (with http2 support).md

Install nginx with http2 support on Ubuntu

  • Backup your nginx.conf files (usually under /etc/nginx/sites-available)
  • Remove old nginx - 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 the following 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
  • fix /etc/nginx/nginx.conf
    • 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
    • or, 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 systemctl stop nginx
sudo systemctl start nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment