which wget || yum -y install wget
nginx_version=1.24.0
which nginx &>/dev/null
if [ $? -ne 0 ];then
wget http://nginx.org/download/nginx-${nginx_version}.tar.gz
tar -xf nginx-${nginx_version}.tar.gz
cd nginx-${nginx_version}
yum -y install pcre-devel openssl-devel make gcc bind-utils
yum -y install geoip-devel

./configure --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx

make && make install
mkdir -p /var/lib/nginx/tmp/client_body
useradd -s /sbin/nologin nginx

# 添加Nginx启动项
cat > /usr/lib/systemd/system/nginx.service << EFO
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EFO
systemctl daemon-reload
systemctl enable nginx.service
systemctl restart nginx.service

else
   nginx -V
fi