Programación de script de Shell script de host virtual Nginx de combate real uno

La característica más importante del servidor web Nginx es que Nginx se usa a menudo para el equilibrio de carga y el proxy inverso. Un único servidor Nginx está configurado con múltiples hosts virtuales, y un centenar de servidores están configurados con N múltiples hosts virtuales. Según los scripts de Shell, los hosts virtuales se pueden configurar y agregar de manera más eficiente. , Gestión. Este punto de conocimiento introduce principalmente el uso de scripts de Shell para implementar la instalación automática de Nginx y el mantenimiento de hosts virtuales.

  1. Determine si el servicio de software WEB Nginx está implementado o en ejecución;
  2. Admite la adición de un único host virtual;
  3. Soporte para agregar múltiples hosts virtuales;
  4. Soporte para eliminar un solo host virtual o múltiples hosts virtuales

Script de implementación específico:

#! / bin / bash

# 6 de marzo de 2020 21:28:16

#auto config nginx vhosts

#por el autor lee

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

# Instalar nginx web

yum install -y wget gzip make tar gcc

yum install -y pcre pcre-devel zlib-devel

wget -c http://nginx.org/download/nginx-1.16.0.tar.gz

tar -xzf nginx-1.16.0.tar.gz

cd nginx-1.16.0

useradd -s / sbin / nologin www -M

./configure --prefix = / usr / local / nginx --user = www --group = www --with-http_stub_status_module

hacer

hacer instalar

/ usr / local / nginx / sbin / nginx

ps -ef | grep nginx

netstat -tnlp | grep -w 80

setenforce 0

systemctl stop firewalld.service

#Config nginx vhosts

cd / usr / local / nginx / conf /

\ cp nginx.conf nginx.conf.bak

grep -vE "# | ^ $" nginx.conf> nginx.conf.swp

sed -i '/ server /, $ d' nginx.conf.swp

echo -e "incluye vhosts / *; \ n}" >> nginx.conf.swp

\ cp nginx.conf.swp nginx.conf

mkdir -p vhosts

cd vhosts

cat> v1.jfedu.net << EOF

servidor {

        escucha 80;

        nombre_servidor v1.jfedu.net;

        ubicación / {

            raíz html / v1.jfedu.net;

            index index.html index.htm;

        }

        error_page 500 502 503 504 /50x.html;

        ubicación = /50x.html {

            raíz html;

        }

}

EOF

mkdir -p /usr/local/nginx/html/v1.jfedu.net

cat> /usr/local/nginx/html/v1.jfedu.net/index.html << EOF

<html>

<head>

         <title> <h1> v1.jfedu.net Páginas de prueba. </h1> </title>

</head>

<cuerpo>

         <hr color = rojo>

</body>

</html>

EOF

/ usr / local / nginx / sbin / nginx -t

/ usr / local / nginx / sbin / nginx -s reload

14 artículos originales publicados · Me gusta0 · Visitas 414

Supongo que te gusta

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