您的位置:首页 > 运维架构 > Apache

Apache配置虚拟主机

2012-11-08 17:58 309 查看
1、 Apache支持配置多个虚拟目录,有的人可能直接在httpd.conf(该文件在:Apache2\conf的目录里)里面配置,今天我是直接配置在:httpd-vhosts.conf(该文件在:Apache2\conf\extra目录里)里。在httpd-vhosts.conf里的文件最后面加入了以下代码:

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host2.localhost

DocumentRoot "d:/web"

ServerName website.cn

</VirtualHost>

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host2.localhost

DocumentRoot "d:/www"

ServerName localhost

</VirtualHost>

我是分了两个目录,分别在D盘得web文件夹和D盘的www文件夹。

访问时分别是:http://website.cn/http://localhost

2、 这里的注意一点,关于website.cn 指向web目录;localhost指向www目录。然后,得找到Windows/system32/drivers/etc/hosts文件打开(用记事本打开),将原来的127.0.0.1 localhost 改为:

127.0.0.1 localhost

127.0.0.1 website.cn

然后,保存。

3、 其次,我们在httpd-vhosts.conf 文件中修改的内容要起作用,要配置httpd.conf文件。启用httpd-vhosts.conf文件的这个模块。在httpd.conf文件中找到如下这句语句:

#Include conf/extra/httpd-vhosts.conf ,把这语句前面的#号去掉,否则httpd-vhosts.conf里的内容不会起作用。去掉之后,保存,重启apache。

如果发现报403错误,请查看是否有“Deny from all ”的信息,试着将
Deny from all -->Deny from allow试试!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: