0
点赞
收藏
分享

微信扫一扫

配置Apache 虚拟主机支持二级域名的两种方法


Apache配置虚拟目录和二级域名[url]http://skyfen.iteye.com/blog/515221[/url]

原文:[url]http://wenku.baidu.com/view/0f292120a5e9856a56126018.html?re=view[/url]

[color=red][b]方法一. 利用 Apache 的 mod_vhost_alias[/b][/color]
引用:

#LoadModule vhost_alias_module modules/mod_vhost_alias.so 去掉前面的#
    <VirtualHost 127.0.0.1:80>
        ServerAdmin hhyisw@163.com
        ServerName x.com
        UseCanonicalName Off
        VirtualDocumentRoot /www/%1.1/%1.1%1.2/%0
    </VirtualHost>


这样的话域名: www.x.com 指向 /www/w/ww/www.x.com


域名:bottle.x.com 指向 /www/b/bo/bottle.x.com



而且新建站分只要建相应目录就可以了,比如新建 new.x.com


那么只要创建目录 /www/n/ne/new.x.com



我测试通过的案例


#add by lzk
<VirtualHost 127.0.0.1:8080>
ServerAdmin hhyisw@163.com
	ServerName testweb.com
	UseCanonicalName Off
	VirtualDocumentRoot E:/FSM-CMS2_WS_2008/WS_Projects/fsmcms_app/trunk/com.fsm.cms.war/war/publish/%1
</VirtualHost>
#需要开放目录权限,否则在访问的时候会提示无权限访问
<Directory "E:/FSM-CMS2_WS_2008/WS_Projects/fsmcms_app/trunk/com.fsm.cms.war/war/publish/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
#
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
</Directory>
#add by lzk



如果输入test1.testweb.com,则对应E:/FSM-CMS2_WS_2008/WS_Projects/fsmcms_app/trunk/com.fsm.cms.war/war/publish/test1


如果输入test2.testweb.com,则对应E:/FSM-CMS2_WS_2008/WS_Projects/fsmcms_app/trunk/com.fsm.cms.war/war/publish/test2



说明:


%0 = 完整的域名 ex: www.stksky.com

%1 = www

 %1+ = www.stksky.com

 %1.1 = w

 %1.2 = w

 %1.3 = w

 %2 = stksky

 %3+ = stksky.com

 %2.1 = s

 %2.2 = t

 %2.3 = k

 …….

 %3 = com

 %3+ = com

 %3.1 = c

 …….


[color=red][b]方法二. 利用 Apache 的 rewrite_module[/b][/color]


引用:



首先,你的拥有一个有泛域名解析的顶级域名,例如: domain.com


其次,在 httpd.conf 中打开 mod_rewrite


之后,在 httpd.conf 的最后,添加以下内容:



RewriteEngine on
    RewriteMap lowercase int:tolower
    RewriteMap vhost txt:/usr/local/etc/apache/vhost.map
    RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
    RewriteCond ${vhost:%1} ^(/.*)$

举报

相关推荐

0 条评论