Skip to content

Instantly share code, notes, and snippets.

@zoghal
Forked from yellowcrescent/nginx_builder_hota.sh
Last active August 29, 2015 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoghal/7dc7a1cbaa4a54091d72 to your computer and use it in GitHub Desktop.
Save zoghal/7dc7a1cbaa4a54091d72 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Nginx build script - jacob@ycnrg.org
#
# Updates code from git/hg repos (or clones if it doesn't exist) for both
# nginx and extra modules, then fires off make
#
# Revision: 3
#
PREFIX="/usr"
SRCBASE="/opt/src"
NGXBASE="/opt/src/nginx"
NGX_BUILD_ID=`hostname`_`date +%Y%m%d`
NGX_CACHE_PURGE="/opt/src/ngx_cache_purge"
NGX_RTMP="/opt/src/nginx-rtmp-module"
NGX_PAGESPEED="/opt/src/ngx_pagespeed"
PSOL_URL="https://dl.google.com/dl/page-speed/psol/1.9.32.2.tar.gz"
NGX_RDNS="/opt/src/nginx-http-rdns"
MJAY="-j`nproc`"
echo "** Preparing to build nginx ${NGX_BUILD_ID} **"
# Update nginx & module friends (or clone their repo if they don't exist)
cd $SRCBASE
echo "Updating nginx..."
if [ -d $NGXBASE ]; then
hg -R $NGXBASE pull
else
hg clone http://hg.nginx.org/nginx
fi
echo "Updating module [ngx_cache_purge]..."
if [ -d $NGX_CACHE_PURGE ]; then
git -C $NGX_CACHE_PURGE pull origin master
else
git clone https://github.com/FRiCKLE/ngx_cache_purge.git
fi
echo "Updating module [ngx-rtmp-module]..."
if [ -d $NGX_RTMP ]; then
git -C $NGX_RTMP pull origin master
else
git clone https://github.com/arut/nginx-rtmp-module.git
fi
echo "Updating module [ngx_pagespeed]..."
if [ -d $NGX_PAGESPEED ]; then
git -C $NGX_PAGESPEED pull origin master
else
git clone https://github.com/pagespeed/ngx_pagespeed.git
fi
echo -en "Checking for psol (Google PageSpeed lib) dependency... "
if [ -d $NGX_PAGESPEED/psol ]; then
echo "Okay, got it!"
else
echo "Missing. Downloading psol module.."
cd $NGX_PAGESPEED
wget "${PSOL_URL}"
echo "Unpacking psol..."
tar -xvf 1.9.32.2.tar.gz
fi
echo "Updating module [ngx_cache_purge]..."
if [ -d $NGX_RDNS ]; then
git -C $NGX_RDNS pull origin master
else
git clone https://github.com/flant/nginx-http-rdns.git
fi
# change to dir and do a `make clean` to get rid of the stale objs
# then run configure with our build args
cd $NGXBASE
if [ -f Makefile ]; then
make clean
fi
if [ ! -f configure ]; then
ln -s auto/configure
fi
./configure \
--build=$NGX_BUILD_ID \
--prefix=$PREFIX \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--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-ipv6 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_spdy_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-mail_ssl_module \
--with-http_mp4_module \
--with-http_flv_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--add-module=$NGX_CACHE_PURGE \
--add-module=$NGX_RTMP \
--add-module=$NGX_PAGESPEED \
--add-module=$NGX_RDNS
#--with-debug
echo "Detected `nproc` cores, running build with $MJAY"
make $MJAY && echo "Build complete! Type 'cd $NGXBASE && sudo make install' to complete the installation." || echo "Build failed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment