前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nginx批量创建虚拟主机自动化脚本

Nginx批量创建虚拟主机自动化脚本

作者头像
用户8449980
修改2021-07-12 10:31:27
6620
修改2021-07-12 10:31:27
举报
文章被收录于专栏:编程学习园地

这篇文章主要为Nginx批量创建虚拟主机脚本,需要的朋友可以参考下。

[root@localhost ~]# vim auto_config_nginx_virtual_host.sh

#!/bin/bash

#2017-12-18 10:31:15

#by author yangxz

#auto Install Nginx

#Define Nginx path variables

NGINX_URL=http://mirrors.yangxingzhen.com/nginx

NGINX_FILE=nginx-1.13.4.tar.gz

NGINX_FILE_DIR=nginx-1.13.4

NGINX_PREFIX=/usr/local/nginx

nginx_install () {

#Install Nginx Soft

yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ wget

wget -c -P /src $NGINX_URL/$NGINX_FILE

tar zxf /src/$NGINX_FILE -C /src

cd /src/$NGINX_FILE_DIR

sed -i 's/1.13.4/ /;s/nginx\//nginx/' /src/nginx-1.13.4/src/core/nginx.h

useradd -s /sbin/nologin www

./configure --prefix=$NGINX_PREFIX \

--user=www \

--group=www \

--with-http_ssl_module \

--with-http_stub_status_module

if [ $? -eq 0 ];then

make &&make install

echo -e "\033[32m NGINX Install success \033[0m"

else

echo -e "\033[32m NGINX Install fail,please check \033[0m"

exit 0

fi

}

nginx_Virtual_Host () {

read -p "Please Enter Server_name:" HOST

if [ -z $HOST ];then

echo -e "\033[32m Please Enter xiaoqi.com|xiaoqi.com admin.com \033[0m"

exit 0

fi

NUM=`grep -c "include vhosts/*" $NGINX_PREFIX/conf/nginx.conf`

if [ $NUM -eq 0 ];then

sed -i '$i\\tinclude vhosts/*;' $NGINX_PREFIX/conf/nginx.conf

if [ ! -d $NGINX_PREFIX/conf/vhosts ];then

mkdir -p $NGINX_PREFIX/conf/vhosts

fi

fi

for i in $HOST

do

cat >$NGINX_PREFIX/conf/vhosts/$i <<EOF

server {

listen 80;

server_name $i;

location / {

root /data/www/$i;

index index.html index.htm;

}

}

EOF

if [ ! -d /data/www/$i ];then

mkdir -p /data/www/$i

fi

cat >/data/www/$i/index.html <<EOF

this is a $i serve

EOF

echo "127.0.0.1 $i" >>/etc/hosts

done

ln -sf $NGINX_PREFIX/sbin/nginx /usr/bin

nginx -t >/dev/null 2>&1

if [ $? -eq 0 ];then

nginx -s reload

else

nginx -t

fi

for k in $HOST

do

curl $k

done

}

PS3="Please Enter select Install Menu[1-3]:"

select i in Install_Nginx-1.13.4 Nginx_Virtual_Host quit

do

case $i in

Install_Nginx-1.13.4)

nginx_install

;;

Nginx_Virtual_Host)

nginx_Virtual_Host $HOST

;;

quit)

echo -e "\033[33m Exit select Menu. \033[0m"

exit 0

esac

done

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
轻量应用服务器
轻量应用服务器(TencentCloud Lighthouse)是新一代开箱即用、面向轻量应用场景的云服务器产品,助力中小企业和开发者便捷高效的在云端构建网站、Web应用、小程序/小游戏、游戏服、电商应用、云盘/图床和开发测试环境,相比普通云服务器更加简单易用且更贴近应用,以套餐形式整体售卖云资源并提供高带宽流量包,将热门软件打包实现一键构建应用,提供极简上云体验。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档