|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +################## |
| 6 | +# VARS |
| 7 | +################## |
| 8 | + |
| 9 | +if [ -z $NGINX_VERSION ] |
| 10 | +then |
| 11 | + echo 'NGINX_VERSION is undefined' |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 16 | + |
| 17 | +NGINXPKG="http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" |
| 18 | +NGINXHEADERSMORE="https://github.com/openresty/headers-more-nginx-module/archive/v0.26.tar.gz" |
| 19 | +NGINXFILTER="https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/v0.6.4.tar.gz" |
| 20 | +NGINXECHO="https://github.com/openresty/echo-nginx-module/archive/v0.57.tar.gz" |
| 21 | +NGINXUPSTREAM="https://github.com/yaoweibin/nginx_upstream_check_module.git" |
| 22 | +NPS_VERSION=1.9.32.3 |
| 23 | +NGINXPAGESPEED="https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}-beta.tar.gz" |
| 24 | + |
| 25 | +################## |
| 26 | +# FCT |
| 27 | +################## |
| 28 | + |
| 29 | +function getPackage() { |
| 30 | + mkdir $2 |
| 31 | + curl -L# $1 | tar -zx --strip 1 -C $2 |
| 32 | +} |
| 33 | + |
| 34 | +################## |
| 35 | +# BEGIN |
| 36 | +################## |
| 37 | + |
| 38 | +cd |
| 39 | +mkdir -p nginx_install && cd nginx_install |
| 40 | + |
| 41 | +# Install pkgs |
| 42 | +apt-get -qq update && \ |
| 43 | +apt-get -qq install -y \ |
| 44 | + curl build-essential libpcre3-dev libgeoip-dev libssl-dev \ |
| 45 | + git \ |
| 46 | + zlib1g-dev libpcre3 unzip |
| 47 | + |
| 48 | +# Get nginx and prepare modules |
| 49 | +getPackage $NGINXPKG nginx |
| 50 | +getPackage $NGINXHEADERSMORE headersmore |
| 51 | +getPackage $NGINXFILTER substitution |
| 52 | +getPackage $NGINXECHO nginxecho |
| 53 | +git clone $NGINXUPSTREAM `pwd`/nginxupstream |
| 54 | +getPackage $NGINXPAGESPEED nginxpagespeed |
| 55 | + |
| 56 | +cd nginxpagespeed |
| 57 | +wget --quiet https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz |
| 58 | +tar -xzf ${NPS_VERSION}.tar.gz |
| 59 | +cd .. |
| 60 | + |
| 61 | +# Build |
| 62 | +cd nginx |
| 63 | +/usr/bin/patch -p1 < ../nginxupstream/check_1.7.5+.patch && \ |
| 64 | +./configure --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2' \ |
| 65 | +--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' \ |
| 66 | +--prefix=/usr/share/nginx \ |
| 67 | +--conf-path=/etc/nginx/nginx.conf \ |
| 68 | +--http-log-path=/var/log/nginx/access.log \ |
| 69 | +--error-log-path=/var/log/nginx/error.log \ |
| 70 | +--lock-path=/var/lock/nginx.lock \ |
| 71 | +--pid-path=/run/nginx.pid \ |
| 72 | +--with-debug \ |
| 73 | +--with-pcre-jit \ |
| 74 | +--with-ipv6 \ |
| 75 | +--with-http_ssl_module \ |
| 76 | +--with-http_stub_status_module \ |
| 77 | +--with-http_realip_module \ |
| 78 | +--with-http_auth_request_module \ |
| 79 | +--with-http_gzip_static_module \ |
| 80 | +--without-http_browser_module \ |
| 81 | +--without-http_geo_module \ |
| 82 | +--without-http_memcached_module \ |
| 83 | +--without-http_referer_module \ |
| 84 | +--without-http_scgi_module \ |
| 85 | +--without-http_split_clients_module \ |
| 86 | +--without-http_ssi_module \ |
| 87 | +--without-http_userid_module \ |
| 88 | +--without-http_uwsgi_module \ |
| 89 | +--add-module=../headersmore/ \ |
| 90 | +--add-module=../substitution/ \ |
| 91 | +--add-module=../nginxecho/ \ |
| 92 | +--add-module=../nginxupstream/ \ |
| 93 | +--add-module=../nginxpagespeed/ \ |
| 94 | +--with-http_flv_module \ |
| 95 | +--with-mail \ |
| 96 | +--with-http_geoip_module \ |
| 97 | +--with-http_spdy_module && \ |
| 98 | +make && make install |
| 99 | + |
| 100 | +STATUS=$? |
| 101 | + |
| 102 | +if [ $STATUS -eq 0 ] |
| 103 | +then |
| 104 | + |
| 105 | + cp -r $DIR/nginx-install/geoip /etc/nginx/ |
| 106 | + cp $DIR/nginx-install/nginx-logrotate /etc/logrotate.d/nginx |
| 107 | + mkdir -p /etc/nginx/conf.d |
| 108 | + |
| 109 | + # Clean install directory |
| 110 | + rm -rf $HOME/nginx_install |
| 111 | + |
| 112 | + echo 'NGINX VERSION: ' && `/usr/share/nginx/sbin/nginx -v` |
| 113 | +else |
| 114 | + echo 'Error...' |
| 115 | + exit 1 |
| 116 | +fi |
| 117 | + |
| 118 | +exit 0 |
0 commit comments