安装
#!/bin/sh
DIR=`pwd`
NGINX_CONF=/usr/local/nginx/conf/nginx.conf
NGINX_CONF_BAK=/usr/local/nginx/conf/nginx.conf.bak
echo "-----------------------------------install nginx-------------------------------"
if [ -d /usr/local/nginx ];then
echo "nginx has installed"
# 解压nginx
tar -xvf nginx-1.19.1.tar.gz
cd nginx-1.19.1
# 替换配置文件
## 备份原来的文件
mv -f $NGINX_CONF $NGINX_CONF_BAK
## 拷贝新文件
cp -f ./conf/nginx.conf $NGINX_CONF
# 重新加载配置文件
service nginx restart
else
if [ $(grep "nginx" /etc/passwd | wc -l) -eq 0 ]; then
echo "adding user nginx"
groupadd nginx
useradd -s /sbin/nologin -M -g nginx nginx
else
echo "user nginx exsits"
fi
echo "-----------------------------------unzip nginx-------------------------------"
tar -xvf nginx-1.19.1.tar.gz
cd nginx-1.19.1
echo "------------------------------------configuring nginx,plz wait----------------------"
./configure --prefix=/usr/local/nginx
if [ $? -ne 0 ];then
echo "configure failed ,please check it out!"
else
echo "make nginx, please wait for 20 minutes"
make
fi
if [ $? -ne 0 ];then
echo "make failed ,please check it out!"
else
echo "install nginx, please wait for 20 minutes"
make install
fi
chown -R nginx.nginx /usr/local/nginx
cd ${DIR}
echo "------------------------------config nginx start----------------------------------------"
cp ./nginx/nginx /etc/init.d/
chmod a+x /etc/init.d/nginx
chkconfig --add /etc/init.d/nginx
chkconfig nginx on
service nginx start
fi
卸载
#!/bin/sh
service nginx stop
rm -rf /usr/local/nginx
rm -rf /etc/init.d/nginx