Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save monkeym4ster/ab7b0eb6850e054854f949b3544844c4 to your computer and use it in GitHub Desktop.

Select an option

Save monkeym4ster/ab7b0eb6850e054854f949b3544844c4 to your computer and use it in GitHub Desktop.

Revisions

  1. @hollodotme hollodotme created this gist Apr 9, 2016.
    87 changes: 87 additions & 0 deletions Install-nginx-with-http2-support.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,87 @@
    # 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:

    ```bash
    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:

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

    Update package cache:

    ```bash
    sudo apt-get update
    ```

    ## Install new nginx

    ```bash
    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`

    ```bash
    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:

    ```bash
    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:

    ```nginx
    listen 443 http2;
    listen [::]:443 http2;
    ```

    Restart nginx:

    ```bash
    sudo service nginx restart
    ```

    Done.