Desenvolvimento de programação SHELL versão de essência de script de gerenciamento de host virtual Nginx

#! / bin / bash

# 8 de março de 2020 15:28:16

#auto config nginx vhosts

#by autor lijingtao

#########################

NGX_VHOST = "$ *"

NGX_VER = "1.16.0"

NGX_CNF = "nginx.conf"

NGX_YUM = "yum instala-y"

NGX_DIR = "/ usr / local / nginx"

NGX_SOFT = "nginx - $ {NGX_VER} .tar.gz"

NGX_URL = "http://nginx.org/download"

NGX_SRC = $ (eco $ NGX_SOFT | sed 's / \. Tar. * // g')

NGX_ARGS = "- usuário = www --group = www --with-http_stub_status_module"

se [$ # -eq 0];

      eco -e "\ 033 [32m -------------------- \ 033 [0m" 

      echo -e "\ 033 [32mUsage: {/ bin / sh $ 0 v1.jf.com | v2.jf.com v3.jf.com | ajuda} \ 033 [0m"  

      saída 1

ser

E se [ ! -d $ NGX_DIR]; em seguida

      #Instalar o nginx web

      $ NGX_YUM wget gzip make tar gcc

      $ NGX_YUM pcre pc-devel zlib-devel

      wget -c $ NGX_URL / $ NGX_SOFT

      tar -xzf $NGX_SOFT

      cd $NGX_SRC

      useradd -s /sbin/nologin www -M

      ./configure --prefix=$NGX_DIR $NGX_ARGS

      make

      make install

      $NGX_DIR/sbin/nginx

      ps -ef|grep nginx

      netstat -tnlp|grep -w 80

      setenforce 0

      systemctl stop firewalld.service

fi

 

#Config nginx vhosts

cd $NGX_DIR/conf/

grep -ai "include vhosts" ${NGX_CNF} >>/dev/null

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 vhosts/*;\n}" >>${NGX_CNF}.swp

      \cp ${NGX_CNF}.swp ${NGX_CNF}

fi

 

mkdir -p vhosts

cd vhosts

 

for NGX_VHOST in $(echo $NGX_VHOST)

do

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

mkdir -p $NGX_DIR/html/$NGX_VHOST

cat>$NGX_DIR/html/$NGX_VHOST/index.html<<EOF

<html>

<h1>$NGX_VHOST Test Pages.</h1>

<hr color=red>

</html>

EOF

cat $NGX_VHOST

$NGX_DIR/sbin/nginx -t >>/dev/null 2>&1

if [ $? -eq 0 ];then

      echo -e "\033[32mnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok\033[0m"

      echo -e "\033[32mnginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful\033[0m"

      $NGX_DIR/sbin/nginx -s reload

fi

done

发布了14 篇原创文章 · 获赞 0 · 访问量 414

Acho que você gosta

Origin blog.csdn.net/falnet/article/details/104736447
Recomendado
Clasificación