Skip to content

Instantly share code, notes, and snippets.

@rcguy
Created Jan 23, 2017
Embed
What would you like to do?
#!/bin/bash
# Dependencies
# * checkinstall: package the .deb
# * libpcre3, libpcre3-dev: required for HTTP rewrite module
# * zlib1g zlib1g-dbg zlib1g-dev: required for HTTP gzip module
# vars
OPENSSL_VER="1.1.0c"
NGINX_VER="1.11.8"
NGINX_USER="www-data"
NGINX_GROUP="www-data"
#NGINX_PREFIX="/usr/share/nginx"
NGINX_PREFIX="/usr/local/nginx"
SRC_DIR="$HOME/src"
BUILD_DIR="$HOME/deb"
PKG_RELEASE="1"
#sudo apt update
#sudo apt install checkinstall libpcre3 libpcre3-dev zlib1g zlib1g-dbg zlib1g-dev unzip -y
#rm -rf $SRC_DIR $BUILD_DIR
# Create src and build dirs.
if [ ! -d $SRC_DIR ]; then
mkdir -p $SRC_DIR
fi
if [ ! -d $BUILD_DIR ]; then
mkdir -p $BUILD_DIR
fi
# Compile against OpenSSL to enable NPN
cd $SRC_DIR
if [ ! -f $OPENSSL_VER.tar.gz ]; then
wget https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
tar zxf openssl-$OPENSSL_VER.tar.gz
fi
#rm openssl-$OPENSSL_VER.tar.gz
# Get the Nginx source.
# Best to get the latest mainline release. Of course, your mileage may vary depending on future changes
cd $SRC_DIR
if [ ! -f $NGINX_VER.tar.gz ]; then
wget https://nginx.org/download/nginx-$NGINX_VER.tar.gz
tar zxf nginx-$NGINX_VER.tar.gz
fi
#rm nginx-$NGINX_VER.tar.gz
cd nginx-$NGINX_VER
# Configure nginx.
# This is based on the default package in Debian.
CFLAGS="$(dpkg-buildflags --get CFLAGS)"
LDFLAGS="$(dpkg-buildflags --get LDFLAGS)"
./configure \
--prefix=$NGINX_PREFIX \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--user=$NGINX_USER \
--group=$NGINX_GROUP \
--with-pcre-jit \
--with-http_ssl_module \
--with-threads \
--with-file-aio \
--with-http_v2_module \
--with-ipv6 \
--with-cc-opt="$CFLAGS" \
--with-ld-opt="$LDFLAGS" \
--without-http_uwsgi_module \
--with-openssl=$SRC_DIR/openssl-$OPENSSL_VER
# Make the package.
make -j 2
# Create a .deb package.
# Instead of running `make install`, create a .deb and install from there. This
# allows you to easily uninstall the package if there are issues.
sudo checkinstall --pkgrelease="$PKG_RELEASE" --install=no -y
# copy completed deb to BUILD_DIR
cp $SRC_DIR/nginx-$NGINX_VER/nginx_"$NGINX_VER"-"$PKG_RELEASE"_amd64.deb $BUILD_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment