apache配置--虚拟目录 - andydaopeng

apache配置--虚拟目录

apache在httpd-vhosts.conf中 配置二级域名或者泛域名:

<VirtualHost *:80>

ServerAdmin 846606478@qq.com

DocumentRoot "D:/workspace/php_core"

ServerName zp.com

ServerAlias bbs.test.com blog.test.com #*.test.com 用*表示泛域名 #设置多个二级域名 bbs.test.com blog.test.com

ServerAlias my.test.com

DirectoryIndex math.php #设置默认的访问页面

ErrorLog "logs/my.test.com-error.log"

CustomLog "logs/my.test.com-access.log" common

<Directory />

Options Indexes

Order allow,deny

IndexOptions Charset=UTF-8

Allow from all

</Directory>

</VirtualHost>

Apache在本地建立泛域名虚拟主机:

在本地建立泛域名虚拟主机,可以修改Apache的安装目录下的conf/httpd.conf,如下:

<VirtualHost *:80>

ServerName auciou.com

ServerAlias *.auciou.com

DocumentRoot F:/site/auciou

</VirtualHost>

重启Apache,就可以在本地同时使用auciou.com和xxx.auciou.com在本地访问,xxx为任意的二级域名,实现了泛域名解析。用此方法,也可以在本地建立多个不同域名的泛域名解析的虚拟主机。

在本地测试时,需要修改hosts文件,打开C:\WINDOWS\system32\drivers\etc\hosts,写入这样的句子:

127.0.0.1 ww2.auciou.com

127.0.0.1 ww3.auciou.com

127.0.0.1 ww4.auciou.com

127.0.0.1 wwa.auciou.com

127.0.0.1 user.auciou.com

127.0.0.1 blog.auciou.com

因为hosts本身没有泛域名解析,所以在本地做测试时,二级域名需要在本地的hosts文件一个一个添加。然后手动备份hosts文件,重装系统之后,覆盖此文件即可。

有关泛域名解析,可以参考:

http://www.auiou.com/relevant/00000519.jsp

http://www.auiou.com/relevant/00000432.jsp

http://www.auiou.com/relevant/00000453.jsp (Apache+PHP的简便安装)