linux上nginx添加虚拟主机脚本

适用于我的编译教程,只适合centos6上,mark下,以后直接复制粘贴就行了。

#!/bin/bash
#author merci
#default web dir :/data/www/ 

function add_vhost(){
	read -p "Please input your domain : " domain
	CONF="/usr/local/nginx/conf/vhost/$domain.conf"
	if [ ! -f "$CONF" ]
	then
		mkdir -p /data/www/$domain
		touch /data/www/$domain/index.php
		echo "<?php phpinfo(); ?>" > /data/www/$domain/index.php
		touch $CONF
		echo "server {\n	listen       80;\n	server_name www.$domain $domain;\n	index index.php index.html;\n 	root  /data/www/$domain;\n 	include php.conf;\n}" > $CONF
		/etc/init.d/nginx reload
		echo "Add vhost successfly! please visit http://$domain"
	else
		echo -e "Web config already exist !"
		exit 0
	fi
}
function del_vhost(){
	read -p "Please input the domain you want to delete : " domain
	CONF="/usr/local/nginx/conf/vhost/$domain.conf"
	if [ ! -f "$CONF" ]
	then
		echo -e "Web config not exist !"
		exit 0
	else
		rm -rf $CONF
		/etc/init.d/nginx reload
		echo -e "Web config deleted successfly !"
	fi
}
function list_vhost(){
	vhostlist=`ls /usr/local/nginx/conf/vhost/`
	for a in $vhostlist
	do
		echo $a
	done
}

echo -e "1.Add vhost config !"
echo -e "2.Del vhost config !"
echo -e "3.List vhost config !"
read -p "Please choose id :" c
case $c in
	1 )
		add_vhost
		;;
	2 )
		del_vhost
		;;
	3 )
		list_vhost
		;;
	* )
		echo "Please choose correct"
		;;
esac


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/425.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。