Last active
April 18, 2021 22:04
-
-
Save claudio4/9b3acc7cc446a013f68ad98ab6d39cb8 to your computer and use it in GitHub Desktop.
Download & Build Nginx with OpenSSL and PCRE with version selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$1" == "" ] || [ "$2" == "" ] || [ "$3" == "" ]; then | |
>&2 echo "No enough arguments provided. use ./build_nginx.sh nginx-version PCRE-version openssl-version [install]" | |
exit 1 | |
fi | |
if [ "$4" == "yes" ]; then | |
INSTALL='yes' | |
else | |
INSTALL='no' | |
fi | |
# names of latest versions of each package | |
export NGINX_VERSION=$1 | |
export VERSION_PCRE="pcre-$2" | |
export VERSION_OPENSSL="openssl-$3" | |
export VERSION_NGINX=nginx-$NGINX_VERSION | |
# URLs to the source directories | |
export SOURCE_LIBRESSL=https://www.openssl.org/source/ | |
export SOURCE_PCRE=ftp://ftp.pcre.org/pub/pcre/ | |
export SOURCE_NGINX=http://nginx.org/download/ | |
#Build directory | |
export BPATH=$(pwd)/build | |
# clean out any files from previous runs of this script | |
rm -rf $BPATH | |
# exit on failture | |
set -e | |
mkdir $BPATH | |
# proc for building faster | |
NB_PROC=$(grep -c ^processor /proc/cpuinfo) | |
# grab the source files | |
echo "Download sources" | |
wget -P $BPATH $SOURCE_PCRE$VERSION_PCRE.tar.gz | |
wget -P $BPATH $SOURCE_LIBRESSL$VERSION_OPENSSL.tar.gz | |
wget -P $BPATH $SOURCE_NGINX$VERSION_NGINX.tar.gz | |
# expand the source files | |
echo "Extract Packages" | |
cd $BPATH | |
tar xzf $VERSION_NGINX.tar.gz | |
tar xzf $VERSION_OPENSSL.tar.gz | |
tar xzf $VERSION_PCRE.tar.gz | |
# set where OpenSSL | |
export STATICLIBSSL=$BPATH/$VERSION_OPENSSL | |
# build nginx, with various modules included/excluded | |
echo "Configure & Build Nginx" | |
cd $BPATH/$VERSION_NGINX | |
./configure --with-openssl=$STATICLIBSSL \ | |
--with-ld-opt="-lrt" \ | |
--with-cc-opt="-march=native" \ | |
--sbin-path=/usr/sbin/nginx \ | |
--conf-path=/etc/nginx/nginx.conf \ | |
--error-log-path=/var/log/nginx/error.log \ | |
--http-log-path=/var/log/nginx/access.log \ | |
--with-pcre=$BPATH/$VERSION_PCRE \ | |
--with-http_ssl_module \ | |
--with-http_v2_module \ | |
--with-file-aio \ | |
--with-threads \ | |
--with-ipv6 \ | |
--with-http_gzip_static_module \ | |
--with-http_stub_status_module \ | |
--without-mail_pop3_module \ | |
--without-mail_smtp_module \ | |
--without-mail_imap_module \ | |
--with-http_image_filter_module \ | |
--lock-path=/var/lock/nginx.lock \ | |
--pid-path=/run/nginx.pid \ | |
--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 \ | |
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \ | |
--with-pcre-jit \ | |
--with-http_stub_status_module \ | |
--with-http_realip_module \ | |
--with-http_auth_request_module \ | |
--with-http_addition_module \ | |
--with-http_geoip_module | |
# touch $STATICLIBSSL/.openssl/include/openssl/ssl.h | |
make -j $NB_PROC && sudo checkinstall --pkgname="nginx" --pkgversion="$NGINX_VERSION" \ | |
--provides="nginx" --requires="libc6, libpcre3, zlib1g" --strip=yes \ | |
--stripso=yes --pakdir="$BPATH/nginx" --backup=yes -y --install="$INSTALL" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$(id -u)" -ne 0 ]; then | |
echo 'This script must be run by root' >&2 | |
exit 1 | |
fi | |
apt-get -y install curl wget build-essential libgd-dev libgeoip-dev checkinstall git sudo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment