Skip to content

Instantly share code, notes, and snippets.

@risyasin
Last active August 8, 2020 09:28
Show Gist options
  • Save risyasin/b3602c90bb1fa3d03a6e1847d4fd6b54 to your computer and use it in GitHub Desktop.
Save risyasin/b3602c90bb1fa3d03a6e1847d4fd6b54 to your computer and use it in GitHub Desktop.
Ubuntu 18 Nginx compile with ModSecurity + ModPageSpeed + Headers + Cache purge with Threads support
#!/usr/bin/env bash
set -e
# http://nginx.org/download/nginx-1.16.0.tar.gz
SRC_ROOT=/usr/src
NSRC_ROOT=/usr/src/nginx
NPS_VERSION=1.13.35.2
NGINX_VERSION=1.16.1
### automated tasks
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
mkdir -p ${NSRC_ROOT}
echo "Repo update"
apt-get update
apt-get upgrade
echo "Installing base packages & libs"
apt-get install -y openssl libssl-dev libssl-doc htop iotop iftop xtail fail2ban aria2
apt-get install -y sysstat links libpcre3 libpcre3-dev libssl-dev zlibc zlib1g zlib1g-dev
apt-get install -y perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python
apt-get install -y build-essential zlib1g-dev libpcre3 libpcre3-dev unzip git uuid-dev
echo "Start to compile Nginx & modules, ngx_pagespeed, test-cookie, headers-more, cache-purge"
cd ${NSRC_ROOT}
rm -rf *
####
#aria2c https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}-stable.tar.gz
#tar zxvf incubator-pagespeed-ngx-${NPS_VERSION}-stable.tar.gz
#cd incubator-pagespeed-ngx-${NPS_VERSION}-stable
### https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
#aria2c https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}-x64.tar.gz
#tar -xzvf ${NPS_VERSION}-x64.tar.gz
cd ${NSRC_ROOT}
aria2c http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
cd ${NSRC_ROOT}
aria2c https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz
tar zxvf headers-more-nginx-module-0.33.tar.gz
aria2c https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar zxvf ngx_cache_purge-2.3.tar.gz
#aria2c https://github.com/kyprizel/testcookie-nginx-module/tarball/master
#mv kyprizel-testcookie-nginx-module-*.tar.gz kyprizel-testcookie-nginx.tar.gz
#tar zxvf kyprizel-testcookie-nginx.tar.gz
cd ${NSRC_ROOT}
#git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git
#./configure --with-compat --add-dynamic-module=../ModSecurity-nginx
#./configure --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-compat --add-dynamic-module=../ModSecurity-nginx
cd nginx-${NGINX_VERSION}/
#--with-http_addition_module \
## --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -march=native -mtune=native -D_GLIBCXX_USE_CXX11_ABI=0' \
#
echo "Configuring Nginx"
./configure --conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-poll_module \
--with-threads \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_slice_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-stream \
--with-file-aio \
--with-http_addition_module \
--with-ipv6 \
--with-compat \
--add-module=${NSRC_ROOT}/headers-more-nginx-module-0.33 \
--add-module=${NSRC_ROOT}/ngx_cache_purge-2.3
# ngx_http_modsecurity_module requires the ModSecurity library
# ngx_http_modsecurity_module requires the ModSecurity library
#https://github.com/kyprizel/testcookie-nginx-module
#--add-module=${NSRC_ROOT}/kyprizel-testcookie-nginx-module \
echo "Compiling Nginx"
make -j4
echo "Installing Nginx"
make install
cd ${NSRC_ROOT}
echo "Setting Nginx as a service"
cd /etc/systemd/system/
aria2c https://gist.githubusercontent.com/risyasin/2a981bab7586773d849e/raw/5d8412486147406199494b0d5df4f72b5781e75d/nginx.service
systemctl enable nginx.service
systemctl start nginx.service
## default directories
mkdir -p /web/default
chown -R www-data:www-data /web
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment