Skip to content

Instantly share code, notes, and snippets.

@e7d
Last active November 28, 2017 11:35
Show Gist options
  • Save e7d/a4ff803ddf771978dda2 to your computer and use it in GitHub Desktop.
Save e7d/a4ff803ddf771978dda2 to your computer and use it in GitHub Desktop.
#!/bin/sh
SRC=/usr/src
NGINX_VERSION=1.8.0 # http://nginx.org/en/download.html
NPS_VERSION=1.9.32.6 # https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Update packages list"
apt-get update
echo "Build dependencies"
apt-get -y install curl git build-essential libpcre3-dev libpcre++-dev zlib1g-dev libcurl4-openssl-dev libssl-dev unzip nginx
echo "Download nginx source code"
cd $SRC
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
echo "Download ngx_headers_more module source code"
cd $SRC
git clone https://github.com/openresty/headers-more-nginx-module.git ngx-headersmore
echo "Download NgxFancyIndex module source code"
cd $SRC
git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex
echo "Download Google PageSpeed source code"
cd $SRC
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
echo "Download Google PageSpeed Optimization Libraries source code"
cd $SRC/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 # extracts to psol/
echo "Build binaries"
cd $SRC/nginx-${NGINX_VERSION}
./configure --prefix=/var/www \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-file-aio \
--with-http_ssl_module \
--with-http_spdy_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-ipv6 \
--with-mail \
--with-mail_ssl_module \
--add-module=$SRC/ngx-fancyindex \
--add-module=$SRC/ngx-headersmore \
--add-module=$SRC/ngx_pagespeed-release-${NPS_VERSION}-beta
make
echo "Stop running service"
service nginx stop
echo "Install binaries"
make install
echo "Prepare environment for first start"
mkdir -p /var/www
cp html/* /var/www
echo "Start service"
service nginx start
echo "Cleanup temporary files"
rm -rf $SRC/nginx-${NGINX_VERSION}*
rm -rf $SRC/release-${NPS_VERSION}*
rm -rf $SRC/${NPS_VERSION}*
rm -rf $SRC/ngx_pagespeed-release-*
rm -rf $SRC/ngx-fancyindex*
rm -rf $SRC/ngx-headersmore*
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment