我正在使用 Yosemite 和 Apache 2.4
/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,我该如何修复它?,请指导。
谢谢。
最佳答案
我今天也遇到了同样的问题。
我在这里找到了解决方案:httpd.apache.org/docs/current/vhosts/name-based.html .
主要主持人离开
任何与现有请求不匹配的请求都将由全局服务器配置处理,无论主机名或服务器名称如何。
当您将基于名称的虚拟主机添加到现有服务器,并且虚拟主机参数与预先存在的 IP 和端口组合匹配时,请求现在将由显式虚拟主机处理。在这种情况下,通常明智的做法是创建一个默认虚拟主机,其服务器名称与基本服务器的服务器名称相匹配。同一接口(interface)和端口上但需要单独配置的新域可以添加为后续(非默认)虚拟主机。
关于apache - Apache 2.4 中的 VirtualHost 在使用 http 时替换 DocumentRoot ://localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26610348/