Apache绑定多域名配置多站点

slytop 2011-10-14

Listen 80

ServerNamelocalhost

[email protected]

ServerRoot"d:\Comsenz\Apache2"

DocumentRoot"d:\Comsenz\wwwroot"

LoadModulephp5_module"d:\Comsenz\PHP5\php5apache2_2.dll"

PHPIniDir"d:\Comsenz\PHP5\php.ini"

<Directory"d:\Comsenz\wwwroot">

OptionsIndexesFollowSymLinks

Orderallow,deny

Allowfromall

</Directory>

Alias/icons/"d:\Comsenz\Apache2\icons\"

<Directory"d:\Comsenz\Apache2\icons">

OptionsIndexesMultiViews

AllowOverrideNone

Orderallow,deny

Allowfromall

</Directory>

NameVirtualHost*:80

<VirtualHost*:80>

[email protected]

DocumentRoot"d:\Comsenz\wwwroot"

ServerName*

<IfModulemod_rewrite.c>

RewriteEngineOn

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>

[email protected]

DocumentRoot"d:\Comsenz\wwwroot"

ServerName*

<IfModulemod_rewrite.c>

RewriteEngineOn

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>

[email protected]

DocumentRoot"d:\Comsenz\wwwroot"

ServerName#例:www.baidu.com

<IfModulemod_rewrite.c>

RewriteEngineOn

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>

[email protected]

DocumentRoot"d:\Comsenz\wwwroot2"

ServerName#第二个域名。例:www.google.com

<IfModulemod_rewrite.c>

RewriteEngineOn

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”。扯蛋的说法。如果不知道就不要胡乱指点,浪费一天的时间。结果是实现不了。主机的方法根本没有办法实现。劝告大家不要轻信别人的方法,尤其是在收费的时候,一定要慎重再慎重。希望以上的示例会帮到大家。

以上的#后面的内容为重点:要改成绑定的域名。例可实现。再将文件夹的路径填写正确便可。找了几个月没有找到方法。没想到是这么简单便可实现。多亏没给他钱,要不然这钱也是白花了啊。唉。

Listen80

ServerNamelocalhost

[email protected]

ServerRoot"d:\Comsenz\Apache2"

DocumentRoot"d:\Comsenz\wwwroot"

如果遇到错误是因为这一段代码没有删除,这几行代码留住第一行就可以了,下面的四行都删除,就可以识别两个域名绑定显示不同文件夹的内容了。LISTEN80,只留住这一行,位置不变。其它的不用理会。

重新写一遍完整的例子。

Listen80

LoadModulephp5_module"d:\Comsenz\PHP5\php5apache2_2.dll"

PHPIniDir"d:\Comsenz\PHP5\php.ini"

<Directory"d:\Comsenz\wwwroot">

OptionsIndexesFollowSymLinks

Orderallow,deny

Allowfromall

</Directory>

Alias/icons/"d:\Comsenz\Apache2\icons\"

<Directory"d:\Comsenz\Apache2\icons">

OptionsIndexesMultiViews

AllowOverrideNone

Orderallow,deny

Allowfromall

</Directory>

NameVirtualHost*:80

<VirtualHost*:80>

[email protected]

DocumentRoot"d:\Comsenz\wwwroot"

ServerName#例:www.baidu.com

<IfModulemod_rewrite.c>

RewriteEngineOn

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>

[email protected]

DocumentRoot"d:\Comsenz\wwwroot2"

ServerName#第二个域名。例:www.google.com

<IfModulemod_rewrite.c>

RewriteEngineOn

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>

[email protected]

DocumentRoot"D:/www.abc.com"

ServerNameabc.com

ServerAliaswww.abc.com

<IfModulemod_rewrite.c>

RewriteEngineOn

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>

====================================================================================

用记事本打开httpd-vhosts.conf,该文件在apache\conf\extra,把下面的代码复制进去。

<VirtualHost192.168.1.1:80>

DocumentRoot/www/web/

ServerNameaaa.com

ServerAlias www.aaa.com

ErrorDocument 404 http://www.aaa.com/error.html

ErrorLoghome/linuxpk/log/dummy-aaa.com-error_log

CustomLog home/linuxpk/log/dummy-aaa.com-access_log commom

     <Directory "/www/web/">

OptionsFollowSymLinks

AllowOverrideNone

Orderallow,deny

Allowfromall

</Directory>

</VirtualHost>

<VirtualHost *:80>

     ServerAdmin [email protected]

     DocumentRoot /www/web/

     ServerName aaa.com

     ServerAlias www.aaa.com

     DirectoryIndex index.htm index.html index.php

     DefaultLanguage zh-CN

     AddDefaultCharset GB2312

     ErrorDocument 404 http://www.aaa.com/error.html

     ErrorLog www/log/dummy-aaa.com-error_log

     CustomLog www/log/dummy-aaa.com-access_log commom

     <Directory "/www/web/">

         Options FollowSymLinks

         AllowOverride None

         Order allow,deny

         Allow from all

     </Directory>

     <IfDefine PHP>

         php_admin_flag engine on

         php_admin_flag safe_mode off

         php_admin_value open_basedir none

         php_admin_value session.save_path "/usr/local/tmp/php/session"

         php_admin_value open_basedir "/www/web/usr/local/tmp/php"

    </IfDefine>

</VirtualHost>

例:主机IP是:192.168.1.1

你的主机上有三个域名:

www.a.com 网页文件放在E:webwww1

www.b.com 网页文件放在E:webwww2

www.c.com 网页文件放在E:webwww3

在apache的httpd.conf中加入

#设置不同的域名到不同的目录

NameVirtualHost 192.168.1.1

<VirtualHost 192.168.1.1>

ServerName www.a.com

DocumentRoot "E:webwww1"

</VirtualHost>

<VirtualHost 192.168.1.1>

ServerName www.b.com

DocumentRoot "E:webwww2"

</VirtualHost>

<VirtualHost 192.168.1.1>

ServerName www.c.com

DocumentRoot "E:webwww3"

</VirtualHost>

重起,就ok 了.

Apache VirtualHost Example

<VirtualHost *:80>

     ServerAdmin [email protected]

     DocumentRoot /www/web/

     ServerName abc.com

     ServerAlias www.abc.com

     DirectoryIndex index.htm index.html index.php

     DefaultLanguage zh-CN

     AddDefaultCharset GB2312

     ErrorDocument 404 http://www.abc.com/error.html

     ErrorLog www/log/dummy-abc.com-error_log

     CustomLog www/log/dummy-abc.com-access_log commom

     <Directory "/www/web/">

         Options FollowSymLinks

         AllowOverride None

         Order allow,deny

         Allow from all

     </Directory>

     <IfDefine PHP>

         php_admin_flag engine on

         php_admin_flag safe_mode off

         php_admin_value open_basedir none

         php_admin_value session.save_path "/usr/local/tmp/php/session"

         php_admin_value open_basedir "/www/web/usr/local/tmp/php"

    </IfDefine>

</VirtualHost>

相关推荐

SuiKaSan的自学室 / 0评论 2017-12-08