本地机apache配置基于域名的虚拟主机详解
<p><strong><font>1.打开apache的httpd.conf文件,找到</font></strong><br>
# Virtual hosts<br>
#Include conf/extra/httpd-vhosts.conf<br>
这一段把Include conf/extra/httpd-vhosts.conf前面的"#"去掉。<br><br><strong><font>2.修改位于(win7)c:/windows/system32/drivers/etc/目录下的hosts文件</font></strong><br>
增加一段:127.0.0.1 x.acme.com(你用来访问的域名)<br><br><strong><font>3.我用的是wamp包,所以到c:/wamp/bin/apache/Apache2.2.11/conf/extra目录下</font></strong><br>
修改文件httpd-vhosts.conf<br>
NameVirtualHost默认如下:<br>
NameVirtualHost *:80<br><br><strong>增加:</strong><br>
<VirtualHost *:80><br>
ServerAdmin x@acme.com <br>
DocumentRoot "/var/www/html"<br>
ServerName x.acme.com <br>
ErrorLog "logs/x.acme.com-error.log"<br>
CustomLog "logs/x.acme.com-access.log" common<br>
</VirtualHost><br><br>
改好然后重启服务器。<br>
在浏览器中输入http://x.acme.com就可以到你的目录.<br><br>
当然如果你是想在现有的web服务器上增加虚拟主机,那么原来localhost的服务要能用的话,需要在上面的基础上加点东西:<br>
hosts文件里加上:127.0.0.1 localhost<br>
并在httpd-vhosts.conf文件里增加:<br>
<VirtualHost *:80><br>
ServerAdmin localhost@xxx.com <br>
DocumentRoot "/var/www/"<br>
ServerName localhost <br>
ErrorLog "logs/ localhost-error.log"<br>
CustomLog "logs/ localhost-access.log" common<br>
</VirtualHost></p>
頁:
[1]