#! / bin / bash # 8 de marzo de 2020 15:28:16 #auto config nginx vhosts #por autor lijingtao ######################### NGX_VHOST = "$ *" NGX_VER = "1.16.0" 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 = "- usuario = www --grupo = www --con-http_stub_status_module" si [$ # -eq 0]; entonces echo -e "\ 033 [32m -------------------- \ 033 [0m" echo -e "\ 033 [32m Uso: {/ bin / sh $ 0 v1.jf.com | v2.jf.com v3.jf.com | ayuda} \ 033 [0m" salida 1 ser Si [ ! -d $ NGX_DIR]; luego # Instalar nginx web $ NGX_YUM wget gzip make tar gcc $ NGX_YUM pcre pcre-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 |
SHELL programación desarrollo Nginx virtual host administración script esencia versión
Supongo que te gusta
Origin blog.csdn.net/falnet/article/details/104736447
Recomendado
Clasificación