Skip to content

Instantly share code, notes, and snippets.

@enefry
Last active September 12, 2017 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enefry/ff4c2ae88b44f858ccd51a166b2f6443 to your computer and use it in GitHub Desktop.
Save enefry/ff4c2ae88b44f858ccd51a166b2f6443 to your computer and use it in GitHub Desktop.
nginx install script
echo "--------- Begin Nginx ---------"
echo "--------- install and update tools ---------"
#更新
yum -y update
#安装依赖,以及git
yum -y install gcc openssl-devel pcre-devel zlib-devel libtool gcc-c++ build-essential git make which wget
echo "--------- prepare files ---------"
if [ ! -d nginx ]; then
mkdir nginx
fi
cd nginx
nginx_version=1.12.1
pcre_version=8.40
openssl_version=1.1.0f
zlib_version=1.2.11
nginx_dirName='nginx-'${nginx_version}
nginx_tarFileName=${nginx_dirName}".tar.gz"
pcre_dirName='pcre-'${pcre_version}
pcre_tarFileName=${pcre_dirName}".tar.gz"
openssl_dirName='openssl-'${openssl_version}
openssl_tarFileName=${openssl_dirName}".tar.gz"
zlib_dirName='zlib-'${zlib_version}
zlib_tarFileName=${zlib_dirName}".tar.gz"
# 下载最新版源码
# nginx 官网:
# http://nginx.org/en/download.html
#
url_nginx="http://nginx.org/download/"${nginx_tarFileName}
if [ ! -f ${nginx_tarFileName} ]; then
rm -rf ${nginx_dirName}
echo 'Download '${url_nginx}
wget ${url_nginx}
else
echo ${nginx_dirName}" skip..."
fi
#
# 下载最新版 pcre
# pcre 官网:
# http://www.pcre.org/
#
url_pcre="https://nchc.dl.sourceforge.net/project/pcre/pcre/"${pcre_version}"/"${pcre_tarFileName}
if [ ! -f ${pcre_tarFileName} ]; then
rm -rf ${pcre_dirName}
echo 'Download '${url_pcre}
wget ${url_pcre}
else
echo ${pcre_dirName}" skip..."
fi
#
# 下载最新版 openssl
# opessl 官网:
# https://www.openssl.org/
#
url_openssl="https://www.openssl.org/source/"${openssl_tarFileName}
if [ ! -f ${openssl_tarFileName} ]; then
rm -rf ${openssl_dirName}
echo 'Download '${url_openssl}
wget ${url_openssl}
else
echo ${openssl_dirName}" skip..."
fi
#
# 下载最新版 zlib
# zlib 官网:
# http://www.zlib.net/
#
url_zlib="https://nchc.dl.sourceforge.net/project/libpng/zlib/"${zlib_version}"/"${zlib_tarFileName}
if [ ! -f ${zlib_tarFileName} ]; then
rm -rf ${zlib_dirName}
echo 'Download '${url_zlib}
wget ${url_zlib}
else
echo ${zlib_dirName}" skip..."
fi
#
# 下载扩展
#
if [ ! -d ngx_http_google_filter_module ];then
git clone https://github.com/cuber/ngx_http_google_filter_module
else
cd ngx_http_google_filter_module
git pull
cd ..
fi
#
# 下载 substitutions 扩展
#
if [ ! -d ngx_http_substitutions_filter_module ];then
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
else
cd ngx_http_substitutions_filter_module
git pull
cd ..
fi
echo "--------- uncompress files ---------"
#
# 解压缩
#
if [ ! -d ${nginx_dirName} ]; then
tar xzf ${nginx_tarFileName}
fi
if [ ! -d ${pcre_dirName} ]; then
tar xzf ${pcre_tarFileName}
fi
if [ ! -d ${openssl_dirName} ]; then
tar xzf ${openssl_tarFileName}
fi
if [ ! -d ${zlib_dirName} ]; then
tar xzf ${zlib_tarFileName}
fi
#
# 进入 nginx 源码目录
#
cd ${nginx_dirName}
echo "--------- make and install nginx ---------"
#
# 设置编译选项
#
# 默认:/usr/local/nginx
./configure \
"--sbin-path=/etc/nginx/sbin/nginx" \
"--conf-path=/etc/nginx/conf/nginx.conf" \
"--error-log-path=/etc/nginx/logs/error.log" \
"--http-log-path=/etc/nginx/logs/access.log" \
"--pid-path=/etc/nginx/var/nginx.pid" \
"--lock-path=/etc/nginx/var/nginx.lock" \
"--without-select_module" "--without-poll_module" "--with-http_realip_module" \
"--with-http_sub_module" "--with-http_gzip_static_module" "--with-http_stub_status_module" \
"--without-http_ssi_module" "--without-http_userid_module" \
"--without-http_ssi_module" "--without-http_userid_module" \
"--without-http_geo_module" "--without-http_map_module" "--without-mail_pop3_module" \
"--without-mail_imap_module" "--without-mail_smtp_module" \
--with-pcre=../${pcre_dirName} \
--with-openssl=../${openssl_dirName} \
--with-zlib=../${zlib_dirName} \
--with-http_ssl_module \
--with-http_v2_module \
--add-module=../ngx_http_google_filter_module \
--add-module=../ngx_http_substitutions_filter_module \
make && make install
echo "--------- Done ---------"
exit 0
------------- centos 7 -------------
/usr/lib/systemd/system/nginx.service
------------- centos 7 -------------
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/etc/nginx/var/nginx.pid
ExecStart=/etc/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
------------- centos 7 -------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment