#!/bin/sh
#*创建时间:2023-11-28                            *#
#*作者:yangjie                                    *#
#*文件描述:nginx安装脚本                          *#


export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bini

Install_nginx() {
	setenforce 0
	yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel
	nginx_version="1.24.0"
	nginx_user="pengrui"
	nginx_group="pengrui"
	nginx_install_dir="/etc/nginx"
	echo "========== Start installing nginx ============"
    cd nginx
	tar zxf nginx-${nginx_version}.tar.gz
	cd nginx-${nginx_version}
	echo "======== make && make install nginx =========="
    ./configure --prefix=${nginx_install_dir} --modules-path=${nginx_install_dir}/modules --user=${nginx_user} --group=${nginx_user} --with-http_realip_module --with-http_v2_module --with-http_sub_module --with-http_addition_module --with-http_secure_link_module --with-http_ssl_module --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-stream --with-http_slice_module  --with-threads --with-http_gzip_static_module --with-http_gunzip_module --with-http_stub_status_module  
	make && make install	
	chown pengrui:pengrui -R ${nginx_install_dir}	
	cat > /etc/systemd/system/nginx.service << EOF
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=${nginx_install_dir}/logs/nginx.pid
ExecStartPre=${nginx_install_dir}/sbin/nginx -t
ExecStart=${nginx_install_dir}/sbin/nginx -c ${nginx_install_dir}/conf/nginx.conf
ExecReload=${nginx_install_dir}/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

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

}

Install_nginx
