Skip to content

Instantly share code, notes, and snippets.

@risyasin
Last active February 26, 2018 13:28
Show Gist options
  • Save risyasin/fc0a6e932ba837c1d20b to your computer and use it in GitHub Desktop.
Save risyasin/fc0a6e932ba837c1d20b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
SRC_ROOT=/usr/src
NSRC_ROOT=/usr/src/nginx
NPS_VERSION=1.13.35.1
NGINX_VERSION=1.12.2
NODEJS_VERSION=8.9.4
## not installing now, uncomment webmin install below
WEBMIN_VERSION=1.870
### automated tasks
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Removing apparmor"
systemctl disable apparmor.service
update-rc.d -f apparmor remove
apt-get purge apparmor
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 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
cd ${SRC_ROOT}
#echo "Installing Webmin"
#aria2c http://prdownloads.sourceforge.net/webadmin/webmin_${WEBMIN_VERSION}_all.deb
#dpkg --install webmin_${WEBMIN_VERSION}_all.deb
#rm -f webmin_${WEBMIN_VERSION}_all.deb
echo "Start to compile Nginx & modules, ngx_pagespeed, test-cookie, headers-more, cache-purge"
echo "Sources will be downloaded to ${SRC_ROOT}"
cd ${NSRC_ROOT}
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz
cd ${NSRC_ROOT}
wget 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.261.tar.gz
tar zxvf headers-more-nginx-module-0.261.tar.gz
aria2c http://labs.frickle.com/files/ngx_cache_purge-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 nginx-${NGINX_VERSION}/
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-http_v2_module --with-http_ssl_module \
--with-http_realip_module --with-http_gzip_static_module \
--with-http_stub_status_module --with-http_sub_module \
--with-file-aio --with-http_addition_module --with-ipv6 \
#--add-module=${NSRC_ROOT}/ngx_pagespeed-release-${NPS_VERSION}-beta \
--add-module=${NSRC_ROOT}/headers-more-nginx-module-0.261 \
--add-module=${NSRC_ROOT}/ngx_cache_purge-2.3
#https://github.com/kyprizel/testcookie-nginx-module
#--add-module=${NSRC_ROOT}/kyprizel-testcookie-nginx-module \
echo "Compiling Nginx"
make
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
echo "Installing nodejs to /opt"
cd /opt/
aria2c https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-linux-x64.tar.gz
tar zxvf node-v${NODEJS_VERSION}-linux-x64.tar.gz
mv node-v${NODEJS_VERSION}-linux-x64 nodejs
rm -rf node-v${NODEJS_VERSION}-linux-x64.tar.gz
ln -s /opt/nodejs/bin/node /usr/bin/node
ln -s /opt/nodejs/bin/npm /usr/bin/npm
node -v
@risyasin
Copy link
Author

curl -fsSL https://gist.githubusercontent.com/risyasin/fc0a6e932ba837c1d20b/raw/390c53186b38761e8c5000f094e5a61a04c1aacc/ubuntu-nginx-compile.sh 

@bsemot
Copy link

bsemot commented Nov 17, 2016

Very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment