【发布时间】:2014-12-23 23:26:23
【问题描述】:
我在 Apache 2.4 中使用 Yosemite
/private/etc/apache2/httpd.conf
ServerName 127.0.0.1:80
DocumentRoot "/Library/WebServer/Documents/"
<Directory "/Library/WebServer/Documents">
Options Multiviews FollowSymLinks
MultiviewsMatch Any
AllowOverride All
Order allow,deny
Allow from all
</Directory>
一切正常,http://localhost 将我引导至默认的/Library/WebServer/Documents/index.html
将Include /private/etc/apache2/extra/httpd-vhosts.conf添加到/private/etc/apache2/httpd.conf后
并将下面的配置添加到 /private/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin admin@xxx.com
ServerName xxx.local
DocumentRoot "/Library/WebServer/Documents/xxx"
<Directory "/Library/WebServer/Documents/xxx/">
Options +FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
当在浏览器中使用 http://localhost 和 http://127.0.0.1 时,Apache 将我定向到 /Library/WebServer/Documents/xxx/index.html 而不是 /Library/WebServer/Documents /index.html,如何解决?请指导。
谢谢。
【问题讨论】:
-
“修复”是什么意思?这完全是意料之中的行为...如果您想要的话,为什么不将
DocumentRoot更改为/Library/WebServer/Documents? -
很抱歉,我错过了
DocumentRoot "/Library/WebServer/Documents/",它已经在文件 httpd.conf 中,但我仍然有这个问题 -
但是现在你的
DocumentRoot是/Library/WebServer/Documents/xxx而不是/Library/WebServer/Documents/所以显然问题仍然存在。 -
@arco444 没错,其实
DocumentRoot已经出现了但是我只是忘记在帖子中提到了,http://localhost指向VirtualHost的DocumentRoot中指定的路径 -
如果
httpd-vhosts.conf不是您想要的DocumentRoot所在的位置,您为什么不直接删除包含的httpd-vhosts.conf文件?一旦定义了 VirtualHost,它将优先于默认设置。
标签: apache virtualhost