-
-
Save zoghal/054747e0c289fe0f334b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# names of latest versions of each package | |
export NGINX_VERSION=1.7.10 | |
export VERSION_NGINX=nginx-$NGINX_VERSION | |
export VERSION_LIBRESSL=libressl-2.1.4 | |
export VERSION_PCRE=pcre-8.36 | |
# URLs to the source directories | |
export SOURCE_NGINX=http://nginx.org/download/ | |
export SOURCE_LIBRESSL=ftp://ftp.openbsd.org/pub/OpenBSD/LibreSSL/ | |
export SOURCE_PCRE=ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ | |
# set where LibreSSL and nginx will be built | |
export BPATH=$(pwd)/build | |
export STATICLIBSSL=$BPATH/$VERSION_LIBRESSL | |
# clean out any files from previous runs of this script | |
rm -rf build | |
mkdir build | |
# ensure that we have the required software to compile our own nginx | |
sudo apt-get update \ | |
&& sudo apt-get -y install curl wget build-essential libgd2-xpm-dev libgeoip-dev checkinstall libxslt-dev | |
# grab the source files | |
echo "Download sources" | |
wget -P ./build $SOURCE_NGINX$VERSION_NGINX.tar.gz | |
wget -P ./build $SOURCE_LIBRESSL$VERSION_LIBRESSL.tar.gz | |
wget -P ./build $SOURCE_PCRE$VERSION_PCRE.tar.gz | |
# expand the source files | |
cd build | |
tar xzf $VERSION_NGINX.tar.gz | |
tar xzf $VERSION_LIBRESSL.tar.gz | |
tar xzf $VERSION_PCRE.tar.gz | |
cd ../ | |
# build static LibreSSL | |
echo "Configure & Build LibreSSL" | |
cd $STATICLIBSSL | |
./config LDFLAGS=-lrt --prefix=${STATICLIBSSL}/.openssl/ \ | |
&& make install-strip | |
# remove the old default nginx config directories generated by previous runs of this script | |
rm -rf /etc/nginx-default | |
# make the current live nginx the new back-up nginx | |
mv /etc/nginx /etc/nginx-bk | |
mkdir /etc/nginx | |
# build nginx, with various modules included/excluded | |
echo "Configure & Build Nginx" | |
cd $BPATH/$VERSION_NGINX | |
./configure \ | |
--with-openssl=$STATICLIBSSL \ | |
--with-pcre=$BPATH/$VERSION_PCRE \ | |
--with-ld-opt="-lrt" \ | |
--prefix=/usr/local/nginx \ | |
--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-debug \ | |
--with-pcre-jit \ | |
--with-ipv6 \ | |
--with-http_ssl_module \ | |
--with-http_stub_status_module \ | |
--with-http_realip_module \ | |
--with-http_auth_request_module \ | |
--with-file-aio \ | |
--with-http_spdy_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_secure_link_module \ | |
--with-http_sub_module \ | |
--with-http_xslt_module | |
touch $STATICLIBSSL/.openssl/include/openssl/ssl.h | |
make \ | |
&& sudo checkinstall --pkgname="nginx-libressl" --pkgversion="$NGINX_VERSION" \ | |
--provides="nginx" --requires="libc6, libpcre3, zlib1g" --strip=yes \ | |
--stripso=yes --backup=yes -y --install=yes | |
# rename the compiled default /etc/nginx directory so it's accessible as a reference to the new nginx defaults | |
mv /etc/nginx /etc/nginx-default | |
# now restore /etc/nginx-bk to /etc/nginx so the old configuration is kept | |
mv /etc/nginx-bk /etc/nginx | |
echo "All done."; | |
echo "This build has not edited your existing /etc/nginx directory."; | |
echo "If things aren't working now you may need to refer to the"; | |
echo "configuration files the new nginx ships with as defaults,"; | |
echo "which are available at /etc/nginx-default"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment