Nginx Webサーバーの最大の機能は、負荷分散とリバースプロキシにNginxがよく使用されることです。単一のNginxサーバーが複数の仮想ホストで構成され、100台のサーバーが複数の仮想ホストで構成されます。シェルスクリプトに基づいて、仮想ホストをより効率的に構成および追加できます、管理。このナレッジポイントでは、主に、Nginxの自動インストールと仮想ホストのメンテナンスを実装するためのシェルスクリプトの使用を紹介しています。
- Nginx WEBソフトウェアサービスがデプロイまたは実行されているかどうかを確認します。
- 単一の仮想ホストの追加をサポートします。
- 複数の仮想ホストの追加をサポートします。
- 単一の仮想ホストまたは複数の仮想ホストの削除をサポート
特定の実装スクリプト:
#!/ bin / bash
#2020年3月6日21:28:16
#auto config nginx vhosts
#作者リー
#########################
#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
作る
インストールする
/ 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 "include vhosts / *; \ n}" >> nginx.conf.swp
\ cp nginx.conf.swp nginx.conf
mkdir -p vhosts
cd vhosts
cat> v1.jfedu.net << EOF
サーバー{
80を聞く;
server_name v1.jfedu.net;
場所/ {
ルートhtml / v1.jfedu.net;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
場所= /50x.html {
ルートhtml;
}
}
EOF
mkdir -p /usr/local/nginx/html/v1.jfedu.net
cat> /usr/local/nginx/html/v1.jfedu.net/index.html << EOF
<html>
<ヘッド>
<title> <h1> v1.jfedu.netテストページ。</ h1> </ title>
</ head>
<ボディ>
<hr color = red>
</ body>
</ html>
EOF
/ usr / local / nginx / sbin / nginx -t
/ usr / local / nginx / sbin / nginx -s reload