日期:2014-05-16  浏览次数:20936 次

Apache绑定多域名配置多站点

Listen 80
ServerName localhost
ServerAdmin webmaster@domain.com
ServerRoot "d:\Comsenz\Apache2"
DocumentRoot "d:\Comsenz\wwwroot"
LoadModule php5_module "d:\Comsenz\PHP5\php5apache2_2.dll"
PHPIniDir "d:\Comsenz\PHP5\php.ini"
<Directory "d:\Comsenz\wwwroot">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
Alias /icons/? ?"d:\Comsenz\Apache2\icons\"
<Directory "d:\Comsenz\Apache2\icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin sy-0099@21cn.com
DocumentRoot "d:\Comsenz\wwwroot"
ServerName *
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3
</IfModule>
</VirtualHost>
重要是改这里:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin sy-0099@21cn.com
DocumentRoot "d:\Comsenz\wwwroot"
ServerName *
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3
</IfModule>
</VirtualHost>
下面是改过的例子,可以实现:多域名显示不同文件夹的内容。
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin sy-0099@21cn.com
DocumentRoot "d:\Comsenz\wwwroot"
ServerName # 例:www.baidu.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3
</IfModule>
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin sy-0099@21cn.com
DocumentRoot "d:\Comsenz\wwwroot2"
ServerName #第二个域名。例:www.google.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/([a-z0-9-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3
RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3
</IfModule>
</VirtualHost>
上面的是绝对的例子,可以完成实现多域名绑定同一IP服务器,而且显示不同文件夹内容,上面的第一个域名(WWW。BAIUCOM)显示的是WWWROOT里面的内容。下面的第二个域名显示的是(WWW。GOOGLE。COM)显示的是WWWROOT2里面的内容,两个都是根目录。可以完全实现多域名绑定,显示不同文件夹内容。严重鄙视用户名:“xiaoyuwxz”。扯蛋的说法。如果不知道就不要胡乱指点,浪费一天的时间。结果是实现不了。主机的方法根本没有办法实现。劝告大家不要轻信别人的方法,尤其是在收费的时候,一定要慎重再慎重。希望以上的示例会帮到大家。
以上的#后面的内容为重点:要改成绑定的域名。例可实现。再将文件夹的路径填写正确便可。找了几个月没有找到方法。没想到是这么简单便可实现。多亏没给他钱,要不然这钱也是白花了啊。唉。
Listen 80
ServerName localhost
ServerAdmin webmaster@domain.com
ServerRoot "d:\Comsenz\Apache2"
DocumentRoot "d:\Comsenz\wwwroot"
如果遇到错误是因为这一段代码没有删除,这几行代码留住第一行就可以了,下面的四行都删除,就可以识别两个域名绑定显示不同文件夹的内容了。LISTEN 80,只留住这一行,位置不变。其它的不用