使用脚本部署源码nginx,并启动

#!/bin/bash
#by Anasta in 1.0-2018.5.7
#使用脚本部署源码nginx,并启动nginx
red='\e[31m'    # 设置颜色,以便打印提示语句
end='\e[0m'

echo -e "$red Download nginx $end"
rpm -q wget &> /dev/null    # 查询是否有安装wget包
if [ $? -ne 0 ];then        # $?非零则说明没有安装
        yum -y install wget
fi
wget http://nginx.org/download/nginx-1.14.0.tar.gz
version=nginx-1.14.0.tar.gz
id nginx &>/dev/null    # 为nginx进程准备运行的用户,判断是否有这个用户(nginx)
if [ $? -ne 0 ];then    # 没有则才去创建这个用户
        useradd nginx -s /sbin/nologin -M
fi

yum -y install gcc gcc-c++ make openssl-devel pcre-devel zlib-devel links

tar xf ./$version -C /usr/local/src    # 将当前文件夹刚下载的nginx包解压到/usr/local/src
cd /usr/local/src/${version%.tar*}     # 进入刚所解压的文件夹中
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module --with-pcre && make && make install
if [ $? -eq 0 ];then
        echo -e "$red nginx install finish,ready start nginx. $end"
        /usr/local/nginx/sbin/nginx
        ss -antp |grep :80
else
        echo -e "$red nginx install failed. $end"
        exit
fi

echo "Hello World!" > /usr/local/nginx/html/index.html # 在主页添加一行内容
links --dump 127.0.0.1

猜你喜欢

转载自blog.csdn.net/anasta198110/article/details/80262775