zoukankan      html  css  js  c++  java
  • Nginx-多功能脚本

    #!/bin/bash
    #2020年2月16日
    #auto_install_nginx_web.v3
    #by fly
    ################################
    #NGX_VER="$1"
    NGX_CNF="nginx.conf"
    NGX_YUM="yum install -y"
    NGX_DIR="/usr/local/nginx"
    NGX_SOFT="nginx-${NGX_VER}.tar.gz"
    NGX_URL="http://nginx.org/download"
    NGX_SRC="$(echo ${NGX_SOFT}|sed 's/.tar.*//g')"
    NGX_ARGS="--user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module"
    #安装nginx
    function nginx_install(){
        $NGX_YUM gcc-c++ pcre pcre-devel zlib zlib-devel 
        $NGX_YUM wget make openssl openssl-devel net-tools
        cd /usr/src
        read -p "请选择版本号:(1.12.0|1.14.0|1.15.0|1.16.0):" NGX_VER
        NGX_SOFT="nginx-${NGX_VER}.tar.gz"
        NGX_SRC="$(echo ${NGX_SOFT}|sed 's/.tar.*//g')"
        wget -c $NGX_URL/$NGX_SOFT
        tar -xf $NGX_SOFT
        cd $NGX_SRC
        useradd nginx
        ./configure --prefix=$NGX_DIR $NGX_ARGS
        make && make install
        $NGX_DIR/sbin/nginx
        ps -ef|grep nginx
        netstat -nutlp|grep -w 80
        #setenforce 0
        sed -i '/SELIUNX/s/enforcing/disabled/g'  /etc/selinux/config
        systemctl stop firewalld.service
        echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
        echo -e "33[32m nginx安装成功. 33[0m"
        $NGX_DIR/sbin/nginx -v
        exit
    }
    #卸载nginx
    function nginx_remove(){
        rm -rf $NGX_SOFT
        rm -rf $NGX_DIR
        netstat -nutlp|grep 80
        systemctl stop firewalld
        pkill nginx
        ps -ef |grep nginx
        echo -e "33[32m nginx已卸载. 33[0m"
        exit
    }
    #升级nginx
    function nginx_update(){
        $NGX_YUM gcc-c++ pcre pcre-devel zlib zlib-devel
            $NGX_YUM wget make openssl openssl-devel net-tools
            cd /usr/src
        read -p "请选择版本号:(1.12.0|1.14.0|1.15.0|1.16.0):" NGX_VER
        NGX_SOFT="nginx-${NGX_VER}.tar.gz"
        NGX_SRC="nginx-$NGX_VER"
            wget -c $NGX_URL/$NGX_SOFT
            tar -xf $NGX_SOFT
            cd $NGX_SRC
            useradd nginx
            ./configure --prefix=$NGX_DIR $NGX_ARGS
        make
        mv $NGX_DIR/sbin/nginx $NGX_DIR/sbin/nginx.old
        cp objs/nginx $NGX_DIR/sbin/
        $NGX_DIR/sbin/nginx -t
        $NGX_DIR/sbin/nginx -s reload
        netstat -nutlp|grep 80
        systemctl stop firewalld
        echo -e "33[32m nginx升级成功. 33[0m"
        $NGX_DIR/sbin/nginx -v
        exit
    }
    
    #添加虚拟主机
    function virtual_add(){
    #NGX_VHOST="$1"
    cd $NGX_DIR/conf
    grep -ai "include vhost" $NGX_CNF >>/dev/null 2>&1
    if [ $? -ne 0 ];then
            cp $NGX_CNF ${NGX_CNF}.bak
            grep -vE "#|^$" $NGX_CNF >${NGX_CNF}.swp
            sed -i '/server/,$d' ${NGX_CNF}.swp
            echo -e "    include vhost/*;
    }" >>${NGX_CNF}.swp
            cp ${NGX_CNF}.swp $NGX_CNF
    fi
    mkdir -p vhost
    cd vhost
    read -p "请输入域名:(vv1.jf.com|vv2.jf.com|vv3.jf.com):" NGX_VHOST
    cat>$NGX_VHOST<<EOF
    server {
            listen       80;
            server_name  $NGX_VHOST;
            location / {
                root   html/$NGX_VHOST;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    }
    EOF
    cat $NGX_VHOST
    mkdir -p $NGX_DIR/html/$NGX_VHOST
    cat>$NGX_DIR/html/$NGX_VHOST/index.html<<EOF
    <h1>$NGX_VHOST Test Pages.</h1>
    <hr color-red>
    EOF
    $NGX_DIR/sbin/nginx -t >>/dev/null 2>&1
    if [ $? -eq 0 ];then
            echo -e "33[32mnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok33[0m"
            echo -e "33[32mnginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful33[0m"
            echo -e "33[32m虚拟主机已添加!!!33[0m"
            $NGX_DIR/sbin/nginx -s reload
            exit
    fi
    }
    
    #删除虚拟主机
    function virtual_del(){
    #NGX_VHOST="$1"
    read -p "请输入域名:(vv1.jf.com|vv2.jf.com|vv3.jf.com):" NGX_VHOST
    cd $NGX_DIR/conf/vhost/
    ls ./
    rm -rf $NGX_VHOST
    rm -rf $NGX_DIR/html/$NGX_VHOST
    $NGX_DIR/sbin/nginx -t >>/dev/null 2>&1
    if [ $? -eq 0 ];then
            echo -e "33[33mnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok33[0m"
            echo -e "33[33mnginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful33[0m"
            echo -e "33[33m虚拟主机已删除!!!33[0m"
            $NGX_DIR/sbin/nginx -s reload
            exit
    fi
    }
    PS3=`echo -e "33[32m/usr/bin/ $0 1)|2)|3)|4) 版本:33[0m"`
    select i in nginx_install nginx_remove nginx_update virtual_add virtual_del  exit
    do
    case $i in
            nginx_install )
            nginx_install
            ;;
        nginx_remove )
        nginx_remove
        ;;
        nginx_update )
        nginx_update
        ;;
            virtual_add )
            virtual_add $1
            ;;
            virtual_del )
            virtual_del $1
            ;;
            exit )
            ;;
            * )
            echo -e "33[34m------------------------------ }33[0m"
            echo -e "33[34mUsage:{/bin/sh $0 1)安装ningx }33[0m"
            echo -e "33[34mUsage:{/bin/sh $0 2)卸载ningx }33[0m"
            echo -e "33[34mUsage:{/bin/sh $0 3)升级ningx }33[0m"
            echo -e "33[34mUsage:{/bin/sh $0 4)添加虚拟主机 请输入域名:www.xxx.com }33[0m"
            echo -e "33[34mUsage:{/bin/sh $0 5)删除虚拟主机 请输入域名:www.xxx.com }33[0m"
            echo -e "33[34m------------------------------ }33[0m"
            exit
    esac
    done
  • 相关阅读:
    8. Automatic Properties(自动属性)
    egg文件安装
    [翻译]深入理解Tornado——一个异步web服务器
    tornado模板的自动编码问题(autoescape )
    PIL的IOError: decoder jpeg not available错误的排除方法
    MongoDB的更新问题
    easy_install
    _imaging.c:75:20: 致命错误: Python.h:没有那个文件或目录
    各类情感的能量等级&大自然与人类能量级别的关系(转)
    python的装饰器(property)
  • 原文地址:https://www.cnblogs.com/fengyuanfei/p/13797659.html
Copyright © 2011-2022 走看看