search close

Ubuntu NGINX 1.10-1.14

access_time Updated Jun 20, 2021

Add the Package Repositories

We’ll first add in the Signal Sciences apt repositories as this simplifies the installation process.

Ubuntu 20.04 “focal”

Cut-and-paste the following script into a terminal:

sudo apt update
sudo apt-get install -y apt-transport-https wget
wget -qO - https://apt.signalsciences.net/release/gpgkey | sudo apt-key add -
sudo echo "deb https://apt.signalsciences.net/release/ubuntu/ focal main" | sudo tee /etc/apt/sources.list.d/sigsci-release.list && sudo apt-get update

Ubuntu 18.04 “bionic”

Cut-and-paste the following script into a terminal:

sudo apt update
sudo apt-get install -y apt-transport-https wget
wget -qO - https://apt.signalsciences.net/release/gpgkey | sudo apt-key add -
sudo echo "deb https://apt.signalsciences.net/release/ubuntu/ bionic main" | sudo tee /etc/apt/sources.list.d/sigsci-release.list && sudo apt-get update

Ubuntu 16.04 “xenial”

Cut-and-paste the following script into a terminal:

sudo apt-get install -y apt-transport-https wget
wget -qO - https://apt.signalsciences.net/release/gpgkey | sudo apt-key add -
sudo echo "deb https://apt.signalsciences.net/release/ubuntu/ xenial main" | sudo tee /etc/apt/sources.list.d/sigsci-release.list && sudo apt-get update

Ubuntu 14.04 “trusty”

Cut-and-paste the following script:

sudo apt-get install -y apt-transport-https wget
wget -qO - https://apt.signalsciences.net/release/gpgkey | sudo apt-key add -
sudo echo "deb https://apt.signalsciences.net/release/ubuntu/ trusty main" | sudo tee /etc/apt/sources.list.d/sigsci-release.list && sudo apt-get update

Ubuntu 12.04 “precise”

Cut-and-paste the following script:

sudo apt-get install -y apt-transport-https wget
wget -qO - https://apt.signalsciences.net/release/gpgkey | sudo apt-key add -
sudo echo "deb https://apt.signalsciences.net/release/ubuntu/ precise main" | sudo tee /etc/apt/sources.list.d/sigsci-release.list && sudo apt-get update

Enabling Lua for NGINX

For older versions of NGINX, we require NGINX to be built with Lua and Luajit support. It is recommended to first ensure that Lua is installed and enabled for NGINX before enabling the Signal Sciences NGINX module.

  1. The first step is to install the dynamic Lua NGINX Module appropriate for your NGINX distribution:

    NGINX 1.10

    sudo apt-get install nginx110-lua-module

    NGINX 1.11

    sudo apt-get install nginx111-lua-module

    NGINX 1.12.1 and higher

    sudo apt-get install nginx-module-lua
  2. Next we will modify the nginx.conf (default /etc/nginx/nginx.conf) to load the dynamic Lua NGINX module. Directly below the line that starts with pid add:

    load_module modules/ndk_http_module.so;
    load_module modules/ngx_http_lua_module.so;

  3. Restart the NGINX Service to initialize the new module

    sudo service nginx restart

Enable Lua by installing the nginx-extras package with the following command:

sudo apt-get install nginx-extras && sudo service nginx restart

Check that Lua is loaded correctly

To verify that Lua has been loaded properly load the following config(ex: sigsci_check_lua.conf) with nginx:

  # Config just to test for lua jit support
#
# Test from commandline as follows:
# nginx -t -c <explicit path>/sigsci_check_lua.conf
#

# The following load_module directives are required if you have installed
# any of: nginx110-lua-module, nginx111-lua-module, or nginx-lua-module
# for your nginx.org installation.
# Also, for some nginx-1.10.nn installed from nginx-extras package, you may
# need to specify the load directives.
# Given the above uncomment the following:
#
# load_module modules/ndk_http_module.so;
# load_module modules/ngx_http_lua_module.so;

events {
    worker_connections 768;
    # multi_accept on;
}
http {
init_by_lua '

local m = {}
local ngx_lua_version = "dev"

if ngx then
  -- if not in testing environment
  ngx_lua_version = tostring(ngx.config.ngx_lua_version)
  ngx.log(ngx.STDERR, "INFO:", " Check for jit: lua version: ", ngx_lua_version)
end

local r, jit = pcall(require, "jit")
if not r then
  error("ERROR: No lua jit support: No support for SigSci Lua module")
else

  if jit then
    m._SERVER_FLAVOR = ngx_lua_version .. ", lua=" .. jit.version
    if os.getenv("SIGSCI_NGINX_DISABLE_JIT") == "true" then
      nginx.log(ngx.STDERR, "WARNING:", "Disabling lua jit because env var: SIGSCI_NGINX_DISABLE_JIT=", "true")
    end
    ngx.log(ngx.STDERR, "INFO:", " Bravo! You have lua jit support=", m._SERVER_FLAVOR)
  else
    error("ERROR: No luajit support: No support for SigSci")
  end

end

';

}

Example of successfully loading the config and its output:

$ nginx -t -c <your explicit path>/sigsci_check_lua.conf

nginx: [] [lua] init_by_lua:9: INFO: Check for jit: lua version: 10000
nginx: [] [lua] init_by_lua:22: INFO: Bravo! You have lua jit support=10000, lua=LuaJIT 2.0.4
nginx: the configuration file <your explicit path>/sigsci_check_lua.conf syntax is ok
nginx: configuration file <your explicit path>/sigsci_check_lua.conf test is successful

Install and Configure the Signal Sciences NGINX Module

  1. Install the module

    apt-get install sigsci-module-nginx
  2. Add the following to your NGINX configuration file in the http context (default: /etc/nginx/nginx.conf)

    include "/opt/sigsci/nginx/sigsci.conf";
  3. Restart the NGINX Service to initialize the new module

    Ubuntu 14.04 and lower

    sudo restart nginx

    Ubuntu 15.04 and higher

    sudo systemctl restart nginx