WenRou's Blog

新浪微薄腾讯微薄

最新碎语:测试图片碎语哦

您的位置:WenRou's Blog >lnamp> 用vhost.sh命令增加虚拟主机站点

用vhost.sh命令增加虚拟主机站点

一 vhost.sh简介
vhost.sh是一个用shell脚本编写的方便快速建立虚拟主机站点的脚本程序
本文的DOC文档地址 http://www.wdlinux.cn/doc/vhost.sh.doc

二 使用方法
使用ssh软件登录到终端,可直接执行vhost.sh命令.

注意:如不是本人定制的系统及用本人的一键安装包,将没有这个命令
可以下载,如下方式:
wget http://www.wdlinux.cn/in_scripts/vhost.sh.txt
mv  vhost.sh.txt  /bin/vhost.sh
chmod 755 /bin/vhost.sh
就可以使用了

使用方法如下:
[root@wdlinux ~]# vhost.sh

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Add Virtual Host for wdlinux or lanmp,Written by wdlinux
---------------------------------------------------------------
Wdlinux is a customized version of CentOS based, for quick, easy to install web server system
lanmp is a tool to auto-compile & install lamp or lnmp on linux
This script is a tool add virtual host for wdlinux
For more information please visit http://www.wdlinux.cn
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The server is running apache
----------------------------------------------------------------

Pleast input domain:
(Default or Example domain:www.wdlinux.cn):www.kylinux.com

domain:www.kylinux.com
-----------------------------------------

Do you want to add more domain name? (y/n)
y
Input domain name,example(bbs.wdlinux.cn blog.wdlinux.cn):
bbs.kylinux.com

domain alias:kylinux.com bbs.kylinux.com
-----------------------------------------

Allow access_log? (y/n)
y
access_log dir:/www/wdlinux/apache/logs/www.kylinux.com.log
------------------------------------------

Do you want to add ftp Account? (y/n)
y
ftp user name:kylinux
ftp user password:123456

web site infomations:
========================================
domain list:www.kylinux.com kylinux.com bbs.kylinux.com
----------------------------------------
website dir:/www/web/www.kylinux.com
----------------------------------------
conf file:/www/wdlinux/apache/conf/vhost/www.kylinux.com.conf
----------------------------------------
access_log:/www/wdlinux/apache/logs/www.kylinux.com.log
----------------------------------------
ftp account:kylinux password:123456
----------------------------------------
web site is OK
For more information please visit http://www.wdlinux.cn
========================================
上面加粗及下划线的,表示是自己输入的内容
相关的选项,可根据自己的需要来定

更详细的请看 DOC文档教程 http://www.wdlinux.cn/doc/vhost.sh.doc

问题或限制
1 用户名中不能用@符号,否则会创建失败

---------------------------------------------------
修改虚拟主机的配置 ,如上示例
修改 /www/wdlinux/apache/conf/vhost/www.kylinux.com.conf 文件即可,可以用VI等编辑器来修改,或用SFTP下载修改
VI的使用,可参考 http://www.wdlinux.cn/linux_vim

------------------------------------------------------
删除站点的方法 ,用如上示例
删除 /www/wdlinux/apache/conf/vhost/ 目录下的  www.kylinux.com.conf  这个文件
删除 /www/web/ 目录下的 www.kylinux.com  目录
删除用户 执行如下操作,即可完成
rm -f /www/wdlinux/apache/conf/vhost/www.kylinux.com.conf
rm -fr /www/web/www.kylinux.com
userdel kylinux
即可完成
注意,删除目录时如有重要数据切记要备份,否则后果自负
如果运行的是nginx,把相应的目录做修改

 

 

附加 vhost.sh.txt

#!/bin/bash
#
# Web Server Install Script
# Created by wdlinux QQ:12571192
# Url:http://www.wdlinux.cn
# Last Updated 2010.11.19
#


PS_SERVER=`ps ax | grep nginx.conf | grep -v "grep"`
if [[ $PS_SERVER ]];then
 SERVER="nginx"
else
 SERVER="apache"
fi

conf_dir="/www/wdlinux/$SERVER/conf/vhost"
log_dir="/www/wdlinux/$SERVER/logs"
web_dir="/www/web"

function dis_info {
 clear
 echo
 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
 echo "Add Virtual Host for wdlinux or lanmp,Written by wdlinux"
 echo "---------------------------------------------------------------"
 echo "Wdlinux is a customized version of CentOS based, for quick, easy to install web server system"
 echo "lanmp is a tool to auto-compile & install lamp or lnmp on linux"
 echo "This script is a tool add virtual host for wdlinux"
 echo "For more information please visit http://www.wdlinux.cn "
 echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
 echo
 echo "The server is running $SERVER"
 echo "----------------------------------------------------------------"
 echo
}
dis_info;

echo "Pleast input domain:"
read -p "(Default or Example domain:www.wdlinux.cn):" domain
if [[ $domain == "" ]];then
 domain="www.wdlinux.cn "
fi
echo
echo "domain:$domain"
echo "-----------------------------------------"
echo
sdomain=${domain#www.}
if [[ -f "$conf_dir/$domain.conf" ]];then
 echo "$conf_dir/$domain.conf is exists!"
 exit
fi

echo "Do you want to add more domain name? (y/n)"
read more_domain
if [[ $more_domain == "y" || $more_domain == "Y" ]];then
 echo "Input domain name,example(bbs.wdlinux.cn blog.wdlinux.cn):"
 read domain_a
 domain_alias=${sdomain}" "${domain_a}
else
 domain_alias=$sdomain;
fi
echo
echo "domain alias:$domain_alias"
echo "-----------------------------------------"
echo

echo "Allow access_log? (y/n)"
read access_log
if [[ $access_log == "y" || $access_log == "Y" ]];then
 nginx_log="log_format  $domain  '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '
               '\$status \$body_bytes_sent \"\$http_referer\" '
               '\"\$http_user_agent\" \$http_x_forwarded_for';
     access_log  logs/$domain.log  $domain;"
 apache_log="    ErrorLog \"logs/$domain-error_log\"
    CustomLog \"logs/$domain-access_log\" common"
 echo
 echo "access_log dir:"$log_dir/$domain.log
 echo "------------------------------------------"
 echo
else
 nginx_log="access_log off;"
 apache_log=""
fi

echo "Do you want to add ftp Account? (y/n)"
read ftp_account
if [[ $ftp_account == "y" || $ftp_account == "Y" ]];then
 read -p "ftp user name:" ftp_user
 read -p "ftp user password:" ftp_pass
 useradd -d $web_dir/$domain -s /sbin/nologin $ftp_user
 echo "$ftp_pass" | passwd --stdin $ftp_user
 chmod 755 $web_dir/$domain
 echo
else
 echo "Create virtual host directory."
 mkdir -p $web_dir/$domain
 chown -R www.www $web_dir/$domain
fi

if [[ $SERVER == "nginx" ]];then
cat > $conf_dir/$domain.conf<<eof
server {
        listen       80;
        server_name $domain $domain_alias;
        root $web_dir/$domain;
        index  index.html index.php index.htm wdlinux.html;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include fcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
                expires      1d;
        }

        location ~ .*\.(js|css)?$ {
                expires      12h;
        }
 $nginx_log
    }
eof
else
cat > $conf_dir/$domain.conf<<eof
<VirtualHost *:80>
    DocumentRoot "$web_dir/$domain"
    ServerName $domain
    ServerAlias $domain_alias
$apache_log
</VirtualHost>
eof
fi

cat > $web_dir/$domain/index.html<<eof
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test page</title>
</head>

<body>
<div align="center">
  <h1>test page of $domain  </h1>
  <p>Create by vhost.sh of <a href="http://www.wdlinux.cn " target="_blank">www.wdlinux.cn</a> </p>
</div>
</body>
</html>
eof
if [[ $ftp_account == "y" || $ftp_account == "Y" ]];then
 chown $ftp_user $web_dir/$domain/index.html
fi

if [[ $SERVER == "nginx" ]];then
 service nginxd restart
else
 service httpd restart
fi

echo
echo
echo
echo "web site infomations:"
echo "========================================"
echo "domain list:$domain $domain_alias"
echo "----------------------------------------"
echo "website dir:$web_dir/$domain"
echo "----------------------------------------"
echo "conf file:$conf_dir/$domain.conf"
echo "----------------------------------------"
if [[ $access_log == "y" || $access_log == "Y" ]];then
 echo "access_log:$log_dir/$domain.log"
 echo "----------------------------------------"
fi
if [[ $ftp_account == "y" || $access_log == "Y" ]];then
 echo "ftp user:$ftp_user password:$ftp_pass";
 echo "----------------------------------------"
fi
echo "web site is OK"
echo "For more information please visit http://www.wdlinux.cn "
echo "========================================"
 


---

转载请注明本文标题和链接:《用vhost.sh命令增加虚拟主机站点

分享到:

发表评论

38 + 3 =
路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交