#!/bin/bash
ngxVersion=1.9.15.1
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install -y gcc readline-devel pcre-devel openssl-devel libxslt-devel gd-devel perl-ExtUtils-Embed geoip-devel mercurial unzip make sudo wget
cd /usr/local/src/
wget https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip -O ngx_http_substitutions_filter_module-master.zip
unzip ngx_http_substitutions_filter_module-master.zip

wget https://github.com/cuber/ngx_http_google_filter_module/archive/master.zip -O ngx_http_google_filter_module.zip
unzip ngx_http_google_filter_module.zip

groupadd nginx
useradd -g nginx nginx

wget https://openresty.org/download/openresty-$ngxVersion.tar.gz
tar zxvf openresty-$ngxVersion.tar.gz
cd openresty-$ngxVersion
./configure \
--prefix=/usr/local/share/ngx-openresty \
--conf-path=/etc/ngx-openresty/nginx.conf \
--error-log-path=/var/log/ngx-openresty/error.log \
--http-log-path=/var/log/ngx-openresty/access.log \
--pid-path=/var/run/ngx-openresty.pid \
--lock-path=/var/lock/ngx-openresty.lock \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_geoip_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_iconv_module \
--with-http_addition_module \
--with-pcre-jit \
--with-luajit \
--with-ipv6 \
--with-stream \
--with-http_v2_module \
--without-http_redis2_module \
--http-client-body-temp-path=/var/tmp/ngx-client/ \
--http-proxy-temp-path=/var/tmp/ngx-proxy/ \
--http-uwsgi-temp-path=/var/tmp/ngx-uwsgi/ \
--http-scgi-temp-path=/var/tmp/ngx-scgi/ \
--http-fastcgi-temp-path=/var/tmp/ngx-fcgi/ \
--add-module=/usr/local/src/ngx_http_google_filter_module-master/ \
--add-module=/usr/local/src/ngx_http_substitutions_filter_module-master/
make
make install
wget http://list.downsoft.cn/Linux/lua/http_headers.lua -O /usr/local/share/ngx-openresty/lualib/resty/http_headers.lua
wget http://list.downsoft.cn/Linux/lua/http.lua -O /usr/local/share/ngx-openresty/lualib/resty/http.lua
ln -s /usr/local/share/ngx-openresty/nginx/sbin/nginx /usr/local/sbin/nginx
nginx -V
nginx
