Requirement packages:
  • zlib
  • gcc
  • docker
  • OpenSSL
  • PCRE

Source code: Nginx 1.15.4, OpenSSL 1.1.0i, headers-more-nginx-module

drwxr-xr-x  5 root root  100 10:18  1 Th10 headers-more-nginx-module
drwxr-xr-x  9 root root  186 10:16  1 Th10 nginx-1.15.4
drwxr-xr-x 19 root root 4096 10:22  1 Th10 openssl-1.1.0i

Compile nginx
$ cd nginx-1.15.4
$ ./configure --prefix=/etc/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --with-openssl=../openssl-1.1.0i \
    --add-module=../headers-more-nginx-module \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock \
    --http-client-body-temp-path=/var/cache/nginx/client_temp \
    --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
    --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
    --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
    --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
    --user=nginx \
    --group=nginx \
    --with-compat \
    --with-file-aio \
    --with-threads \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_mp4_module \
    --with-http_random_index_module \
    --with-http_realip_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-mail \
    --with-mail_ssl_module \
    --with-stream \
    --with-stream_realip_module \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module
$ make
$ mkdir /tmp/installdir
$ make install DESTDIR=/tmp/installdir
Create script pre-install, post-install

before.sh

#!/bin/bash
# Author: kenshin17
# Date: 01-10-18 10:03
# Description: Script setup environment before install nginx

# Adduser nginx
adduser --system --no-create-home --user-group -s /sbin/nologin nginx

# Config logrotate nginx log
cat <<EOF > /etc/logrotate.d/nginx
/var/log/nginx/*log {
    create 0644 nginx nginx
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}
EOF

# Config init nginx script
curl https://raw.githubusercontent.com/kenshin17/k/master/etc-init.d-nginx -o /etc/init.d/nginx
chmod +x /etc/init.d/nginx

after.sh

#!/bin/bash
# Author: kenshin17
# Date: 01-10-18 10:03
# Description: Script config nginx after install nginx

# Create nginx cached folder
mkdir -p /var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp}

# Create vhost config folder
mkdir -p /etc/nginx/{conf.d,sites.d}

Pull FPM Docker image
docker pull kenshin17/fpm:rpm
Run FPM Docker
docker run -ti -v /tmp/installdir:/tmp/installdir kenshin17/fpm:rpm bash
Create RPM NGINX Package:
$ cd /tmp/installdir
$ fpm -s dir -t rpm -n yourname-nginx --pre-install before.sh --post-install after.sh -v 1.0.0 -C /tmp/installdir -d "logrotate" -d "pcre-devel" -d "zlib-devel" -d "openssl-devel" --description "Nginx compile on nginx 1.15.4 with HTTP2, OpenSSL 1.1.0i, Headers more Nginx module"

Enjoy!