Skip to content

Deploy: Production

Philippe Kalitine edited this page Jun 22, 2017 · 1 revision

We will install NGINX to serve MUTE web application (static files) optimized for production.

Prerequisites

  • Ubuntu 16.04
  • NGINX >= 1.12.0
  • ngx_brotli - NGINX module for Brotli compression

Install

Before we can compile Nginx we need to install the prerequisites:

apt-get install build-essential zlib1g-dev libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libperl-dev

Download the sources

Download the source for Nginx:

cd /usr/local/src
wget http://nginx.org/download/nginx-1.13.0.tar.gz
tar -xzvf nginx-1.13.0.tar.gz

Download the source for the Brotli compression Nginx module from GitHub:

cd /usr/local/src
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
git submodule update --init --recursive

Compile the sources & install

cd /usr/local/src/nginx-1.13.0
./configure --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_gzip_static_module --with-http_v2_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-threads --add-module=/usr/local/src/ngx_brotli --sbin-path=/usr/sbin/nginx
make
apt-get remove nginx
checkinstall

Verify installation

nginx -V

You should see something like:

nginx version: nginx/1.13.0
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_gzip_static_module --with-http_v2_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-threads --add-module=/usr/local/src/ngx_brotli

Run

NGINX configuration file is located at /usr/local/nginx/conf/nginx.conf. This repository contains a template for nginx.conf file (see conf/nginx.conf and conf/nginx.https.conf). It is optimized for MUTE (single page web application, serving static files).

Once the configuration file is modified, start the server:

nginx

Start automatically when the server boots

Save this file as /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Enable the service.

sudo systemctl enable nginx