apache配置多个虚拟目录站点

错误的作法

网上查了几个资料,作法以下:好比想配置两个www.web1.com  www.web2.com站点php

打开httpd.conf ,而后添加:html

1 <VirtualHost *:80>
2 DocumentRoot "d:/github/web1"
3 ServerName www.web1.com
4 </VirtualHost>
5 
6 <VirtualHost *:80>
7 DocumentRoot "d:/github/web2"
8 ServerName www.web2.com
9 </VirtualHost>

 

而后我试了n次,发现访问www.web2.com,打开的是www.web1.com,也就是说只有第一个虚拟站点设置生效了。而后我怀疑是否是DocumentRoot  、<Directory> 或者端口问题,因而改了屡次,仍是不行。git

 

正确的作法

找了多篇文章,终于试验成功了,打开httpd.conf,而后添加:github

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "d:/github/web1"
ServerName www.web1.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "d:/github/web2"
ServerName www.web2.com
</VirtualHost>

从新访问www.web2.com, 正确的打开了www.web2.com内容。web

这段虚拟站点的设置我建议设置在httpd.conf里面,能够将httpd.conf的 #Include conf/extra/httpd-vhosts.conf 的注释#去掉,apache

而后在httpd-vhosts.conf里面设置,这时惊奇的发现httpd-vhosts.conf里面有这句 NameVirtualHost *:80spa

 

 

真的是网上找资料很容易误入歧途,不少人写文章不亲自试验,就摘抄,结果误人子弟。code

最后分享个文章里面总结了apache配置:htm

Apache 的 httpd.conf 详解(很实用)blog

相关文章
相关标签/搜索