nginx脚本自动安装
脚本功能:
- 自动安装nginx
- 自动判别系统是否安装nginx
- 自定义安装nginx路径
- 自定义安装nginx版本。
#!/bin/bash
#2019年10月30日16:00:50
#auto install nginx web
#by author sunjinhua
########################
NGX_USR="www"
NGX_VER="$1"
NGX_YUM="yum install -y"
NGX_SRC="nginx-${NGX_VER}"
NGX_DIR="$2"
NGX_URL="http://nginx.org/download"
NGX_SOFT="${NGX_SRC}.tar.gz"
NGX_ARGS="--user=$NGX_USR --group=$NGX_USR --with-http_stub_status_module"
if [ $# -ne 2]; then
echo -e " 3332m------------------------------ 33[0m"
echo -e " 3332musage:{/bin/sh $0 1.160 /usr/local/nginx/ } 33[0m"
exit
fi
if [ ! -d "$NGX_DIR" ];then
cd $HOME
$NGX_YUM wget gzip tar make gcc
$NGX_YUM pcre pcre-devel zlib-devel openssl-devel
wget -c $NGX_URL/$NGX_SOFT
ls -l $NGX_SOFT
tar -xzf $NGX_SOFT
cd $NGX_SRC
useradd -s /sbin/nologin $NGX_USR -M
./configure --prefix=$NGX_DIR $NGX_ARGS
if [ $? -eq 0 ];then
make
else
echo "please chenck nginx error"
fi
if [ $? -eq 0 ];then
make install
else
echo "plase chenck install nginx error"
fi
$NGX_DIR/sbin/nginx
ps -ef|grep nginx
netstat -tnlp|grep 80
setenforce 0
systemctl stop firewalld.service
fi