Skip to content

Instantly share code, notes, and snippets.

@mansurali901
Last active June 21, 2019 16:26
Show Gist options
  • Save mansurali901/16a6972caf71817ec630fd9e72f9cfde to your computer and use it in GitHub Desktop.
Save mansurali901/16a6972caf71817ec630fd9e72f9cfde to your computer and use it in GitHub Desktop.
Your Nginx Compilation made easy with this script
#!/bin/bash
# Author : Mansur Ul Hasan
# EMail : [email protected]
# Disclaimer :
# This script is well tested on Ubuntu Docker image and latest Ubuntu version along with
# some older versions like Ubuntu 14.04
SetupLoc='/tmp'
Download_Setup () {
# This function download all neccesary files which are required
cd $SetupLoc
apt update -y
apt install build-essential wget curl zip unzip -y
wget https://nginx.org/download/nginx-1.13.1.tar.gz && tar zxvf nginx-1.13.1.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz
rm -rf *.tar.gz
}
Compile_Final () {
# This function compile nginx with various options
cd $SetupLoc/nginx-1.13.1
mkdir /var/lib/nginx/body -p
echo "./configure --prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--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/lock/nginx.lock \
--user=www-data \
--group=www-data \
--build=Ubuntu \
--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-openssl=../openssl-1.1.0f \
--with-openssl-opt=enable-ec_nistp_64_gcc_128 \
--with-openssl-opt=no-nextprotoneg \
--with-openssl-opt=no-weak-ssl-ciphers \
--with-openssl-opt=no-ssl3 \
--with-pcre=../pcre-8.40 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--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_slice_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_secure_link_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-debug \
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' " compile.sh
sh compile.sh
if [ $? -gt 0 ];
then
echo "Compilation completed"...
make
make install
rm -rvf nginx-1.13.1/ openssl-1.1.0f/ pcre-8.40/ zlib-1.2.11/
else
exit
fi
}
ServiceInstall () {
echo '
# Author : Mansur Ul Hasan
# Email : [email protected]
start_init () {
echo "Starting Ngnix .... "
nginx
if [ $? -eq "0" ];
then
echo "Nginx Started .. "
fi
}
stop_init () {
echo "Stopping Ngnix .... "
psu='`ps axu |grep nginx |grep -v grep |awk '{print $2}'`'
kill -9 '$psu'
if [ $? -eq "0" ];
then
echo "Nginx Stopping .. "
fi
}
start1_init () {
echo "Starting Ngnix .... "
nginx
if [ $? -eq "0" ];
then
echo "Nginx Started .. "
fi
}
status_init () {
PIDCOUNT=`ps aux|grep nginx|grep -v grep |wc -l`
if [ $PIDCOUNT -gt 0 ];
then
echo "Nginx is running ..."
else
echo "Nginx is not running"
fi
}
restart_init () {
stop_init
sleep 3
start1_init
}
case $1 in
start)
start_init
;;
stop)
stop_init
;;
restart)
#sleep 2
restart_init
;;
status)
status_init
;;
esac
' > /etc/init.d/nginx
chmod +x /etc/init.d/nginx
}
SetupBegin () {
Download_Setup
Compile_Final
ServiceInstall
}
SetupBegin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment