0
点赞
收藏
分享

微信扫一扫

CentOS下自动安装Nginx脚本

天行五煞 2022-01-25 阅读 94

身为WEB开发人员,在Linux系统下安装Nginx提供WEB Service是必备技能。如果需要经常安装,有个自动化的脚本还是能提高不少效率。上代码:

#!/bin/bash
#------------------------------
#-----Function Update Ningx and PHP for CentOS.
#Author:Mickeywaugh@qq.com. CSDN Mickeywaugh
#------------------------------
DOWNLOAD_DIR="/home/tools/"
if [ -z "$1" ]; then
    NGINX_VER="1.19.2"
else
    NGINX_VER="$1"
fi
NGINX_SRC="http://nginx.org/download/nginx-${NGINX_VER}.tar.gz"
NGINX_CFG="--prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --lock-path=/usr/local/nginx/nginx.lock --error-log-path=/usr/local/nginx/error.log --http-log-path=/usr/local/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client --http-proxy-temp-path=/usr/local/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/fastcgi --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-http_ssl_module --with-http_stub_status_module --add-module=../ngx-fancyindex"
#Downloading install package
#如果源文件不存在则下载
mkdir -p ${DOWNLOAD_DIR}
cd ${DOWNLOAD_DIR}
if [ ! -f "nginx-${NGINX_VER}.tar.gz" ]; then
    wget -c $NGINX_SRC
fi
#如果源文件存在,
if [ -f "nginx-${NGINX_VER}.tar.gz" ]; then
    #则检测是否已解压,如果没有解压文件夹存在,则解压
    if [ ! -d "nginx-${NGINX_VER}" ]; then
        tar -zxvf nginx-${NGINX_VER}.tar.gz
    fi
fi
#进入解压后的文件夹
cd nginx-${NGINX_VER}
#清除可能存在的安装缓存
make clean
#如果没有执行配置过程,则执行配置过程
if [ ! -f "Makefile" ]; then
    ./configure ${NGINX_CFG}
fi
#如果没有出错,则执行编译过程
if [ $? -eq 0 ]; then
    make && make install
    if []; then
        echo "Nginx 安装失败:$2"
    else
        echo "Nginx 安装完成."
    fi
else
    echo "NGINX配置错误!"
    exit 1
fi

代码为个人开发过程中的不断修订,可能不具备通用性。典型运行环境为CentOS7.6+,CentOS8.

举报

相关推荐

0 条评论