#!/usr/bin/env bash
#set -e 和-o errexit相同
set -o errexit
source ./common.sh

yum install gcc  pcre-devel  zlib-devel  openssl-devel -y

NGINX_TMP="/tmp/nginx"
[ ! -e /tmp/nginx ] && mkdir -p $NGINX_TMP
cd $NGINX_TMP

wget http://soft.wujy.vip/nginx-1.18.0.tar.gz
tar xf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/data/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
make -j ${cpu_core_num} && make install 

ln -s /data/nginx/sbin/nginx /usr/bin/

cat > /lib/systemd/system/nginx.service << EOF
[Unit]
##save file as /lib/systemd/system/nginx.service
Description=The NGINX HTTP and reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/data/nginx/logs/nginx.pid 
ExecStartPre=/usr/bin/nginx -t
ExecStart=/usr/bin/nginx
ExecReload=/usr/bin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

systemctl enable nginx 
systemctl start nginx
