Customized Nginx RPM Build

Linux

NGINX / Tengine RPM with Dynamic Modules & LuaJIT

🚀 Features

This custom RPM includes (based on version selected):

  • NGINX 1.x.x or Tengine 3.x.x
  • Dynamic modules:
    • ngx_http_geoip2_module (GeoIP2 support)
    • nginx-module-vts (traffic monitoring)
    • ngx_devel_kit (for Lua support)
    • lua-nginx-module (Lua scripting support)
  • Lua libraries:
    • lua-resty-core
    • lua-resty-lrucache
  • Systemd service integration
  • Built with LuaJIT

🔧 How to Build
1. Install Dependencies
# Centos or RedHat 9
dnf install -y epel-release
dnf config-manager --set-enabled crb
dnf groupinstall -y "Development Tools"
dnf install -y gcc gcc-c++ make autoconf automake libtool \
    pcre pcre-devel zlib zlib-devel openssl openssl-devel \
    libaio-devel libatomic libatomic_ops-devel \
    libmaxminddb libmaxminddb-devel \
    gperftools gperftools-devel \
    luajit luajit-devel git \
    perl-devel perl-ExtUtils-Embed \
    wget unzip git which \
    perl readline-devel systemd-devel
2. Prepare SPEC File
rpmdev-setuptree && git clone https://github.com/Jas0n0ss/ngx-migration.git
# For NGINX
cp ngx-migration/nginx.spec ~/rpmbuild/SPECS/nginx.spec
# For Tengine
cp ngx-migration/tengine.spec ~/rpmbuild/SPECS/tengine.spec

3. Build with build.sh Script

The script automatically detects whether to use nginx.spec or tengine.spec based on the environment variable TENGINE.

# build.sh --help
NGINX=1.25.0 ngx-migration/build.sh
TENGINE=3.1.0 ngx-migration/build.sh
#
TENGINE=3.1.0 GEOIP2=3.4 VTS=0.2.4 \
DEVEL_KIT=0.3.4 LUA_NGINX=0.10.28 LUA_RESTY_CORE=0.1.24 \
LUA_RESTY_LRUCACHE=0.13 ngx-migration/build.sh

💡 At least one of NGINX or TENGINE must be defined. The script will automatically choose nginx.spec or tengine.spec accordingly.


4. RPM Output

After building, you’ll find the RPM(s) here:

~/rpmbuild/RPMS/x86_64/
5. Backup & Install Nginx
# backup 
tar cvzf /tmp/`hostname`-conf-data.tgz /etc/nginx /data/static
# restore
tar xf <hostname>-conf-data.tgz 
cp -r etc/nginx /etc && cp -r data/static /data
wget https://github.com/Jas0n0ss/ngx-migration/releases/download/v1.0/nginx-1.25.0-1.el9.x86_64.rpm
# Install the RPM (example for NGINX):
sudo dnf localinstall nginx-1.25.0-1.x86_64.rpm
# sudo dnf localinstall tengine-3.1.0-1.x86_64.rpm
sudo systemctl enable --now nginx
sudo systemctl status nginx 
6. Enable Dynamic Modules (if needed)

Edit /etc/nginx/nginx.conf and add at the top:

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