How to Manually Compile OpenResty with Nginx, Lua, and Performance Modules on Ubuntu 16.04

This step‑by‑step guide shows how to prepare an Ubuntu 16.04 system, install all required dependencies, download OpenResty and its optional modules, configure the build with performance‑focused options, compile, install, set environment variables, and create a systemd service for automatic startup.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
How to Manually Compile OpenResty with Nginx, Lua, and Performance Modules on Ubuntu 16.04

Introduction

This tutorial explains how to manually compile OpenResty, a high‑performance web platform built on Nginx and Lua, on Ubuntu 16.04 LTS 64‑bit, while avoiding later maintenance costs by using only distribution‑provided dependencies.

Optional Extensions

OpenSSL 1.0.2 with ALPN support for HTTP/2

Nginx‑CT for transparent certificate handling

ngx_PageSpeed for Google‑style performance optimization

Brotli compression (higher ratio than Gzip)

Jemalloc for improved memory management

Environment

The example uses Ubuntu 16.04 LTS 64‑bit.

System Update and Basic Packages

apt update
apt upgrade -y

Prerequisites

Ensure perl (≥5.6.1), libpcre, libssl, and that ldconfig is in the PATH.

Version Variables

Define version variables so future updates only require changing these values.

# Version variables
OpenSSLVersion='openssl-1.0.2n'   # Ubuntu 16.04 default is 1.0.2
NginxCTVersion='1.3.2'
PageSpeedVersion='1.12.34.3'
SystemBit='X64'
OpenRestyVersion='openresty-1.13.6.1'

Install Build Dependencies

sudo apt-get install libpcre3-dev libssl-dev perl make build-essential curl
apt install build-essential libreadline-dev libncurses5-dev libpcre3 libpcre3-dev libssl-dev zlib1g-dev unzip git perl make libjemalloc1 libjemalloc-dev libxml2 libxml2-dev libxslt-dev

Download Source Code

All sources are placed under /root/src for easy management.

cd /root
mkdir src
cd src

Download OpenResty and its extensions:

# OpenSSL (Ubuntu 16.04 already provides 1.0.2)
#wget https://www.openssl.org/source/$OpenSSLVersion.tar.gz
#tar xzf $OpenSSLVersion.tar.gz

wget https://github.com/grahamedgecombe/nginx-ct/archive/v$NginxCTVersion.tar.gz
tar xzf v$NginxCTVersion.tar.gz

git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
git submodule update --init
cd ..

wget https://github.com/apache/incubator-pagespeed-ngx/archive/v$PageSpeedVersion-stable.zip
unzip v$PageSpeedVersion-stable.zip
cd incubator-pagespeed-ngx-$PageSpeedVersion-stable/
wget https://dl.google.com/dl/page-speed/psol/1.12.34.2-$SystemBit.tar.gz
tar -xzvf 1.12.34.2-$SystemBit.tar.gz
cd ..

wget -c https://openresty.org/download/$OpenRestyVersion.tar.gz
tar zxf $OpenRestyVersion.tar.gz

Configure Build

Enter the OpenResty source directory and run ./configure with performance‑oriented options.

cd $OpenRestyVersion

./configure \
  --prefix=/usr/local/openresty \
  --user=www \
  --group=www \
  --with-pcre-jit \
  --with-stream \
  --with-stream_ssl_module \
  --with-stream=dynamic \
  --with-file-aio \
  --with-threads \
  --with-cc-opt="-O3" \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-http_mp4_module \
  --with-http_gzip_static_module \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_xslt_module \
  --with-http_iconv_module \
  --without-http_redis2_module \
  --with-openssl-opt=enable-tlsext \
  -j8

Resolving a Common Error

Solution: sudo apt-get install libxml2 libxml2-dev libxslt-dev

Compile

Build the source. Use parallel jobs if the machine has multiple CPU cores.

make
make -j2   # Example for a 2‑core CPU
Assuming you have 2 CPU cores.

Install

After a successful build, install OpenResty system‑wide.

sudo make install
Root privileges (sudo) are typically required on Linux.

Configure Environment Variables

OpenResty is installed to /usr/local/openresty/. Add its binaries to PATH:

export PATH=/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:$PATH
For Bash, add the line to ~/.bashrc or ~/.bash_profile for persistence.

Create systemd Service

Create /etc/systemd/system/openresty.service using the following content (downloaded from a gist):

cd /etc/systemd/system/
wget https://gist.githubusercontent.com/ivmm/dbf03e6c7970488652878bb8ddc3a775/raw/48436d911d08e57774c759bdb50548dec31dc86f/openresty.service

Reload systemd, restart the service, and enable it at boot:

systemctl daemon-reload
systemctl restart openresty
systemctl enable openresty
After this, accessing the server’s IP shows the OpenResty welcome page.

Replace Default nginx.conf

Download a ready‑made nginx.conf and place it under /usr/local/openresty/nginx/conf/:

cd /usr/local/openresty/nginx/conf/
rm nginx.conf -rf
wget https://gist.githubusercontent.com/ivmm/ab81dee184b64036bd4b8d5abe676264/raw/1cbfbc387aa956f6d9afe39d60e2b8c988a10688/nginx.conf

Finally, test the configuration and reload:

nginx -t
nginx -s reload
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CompilationLuaUbuntusystemd
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.