【问题标题】:Apache ignoring DocumentRootApache 忽略 DocumentRoot
【发布时间】:2016-12-26 05:38:11
【问题描述】:

我正在尝试修改 Apache 中虚拟主机的 DocumentRoot。虚拟主机的 DocumentRoot 设置被忽略,而是使用整个 DocumentRoot。

在我的例子中,Apache 没有使用 /Applications/AMPPS/www/public 作为根文件夹,而是使用 /Applications/AMPPS/www。

httpd.conf 文件的相关部分如下所示。 有没有人看到问题?

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory,  but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Applications/AMPPS/www"

...snip...

<VirtualHost 127.0.0.1:80>
<Directory "/Applications/AMPPS/www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName localhost
ServerAlias localhost 127.0.0.1
ScriptAlias /cgi-bin/ "/Applications/AMPPS/www/cgi-bin/"
DocumentRoot "/Applications/AMPPS/www/public"
ErrorLog "/Applications/AMPPS/apache/logs/error_log"
CustomLog "/Applications/AMPPS/apache/logs/access.log" combined
</VirtualHost>

【问题讨论】:

    标签: apache document-root ampps


    【解决方案1】:

    似乎没有使用VirtualHost,这可以解释为什么主服务器配置中的DocumentRoot 处于活动状态。您可能需要在 VirtualHost 块之前添加 NameVirtualHost。像这样:

    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1:80>
    ...
    

    还要完全删除ServerAlias 指令,因为您在其中的两个整体都没有做任何事情。您不需要在那里复制 localhost 因为您将它作为 ServerName 并且它不接受 IP 地址。 IP 地址将提供给分配给它的第一个匹配的VirtualHost。

    参考:NameVirtualHost Directive

    NameVirtualHost 在 Apache 2.4 中被删除,所以我假设您使用的是早期版本。从 2.4 开始,没有它也可以工作。

    【讨论】:

      猜你喜欢
      • 2012-04-21
      • 2021-01-28
      • 2015-03-18
      • 1970-01-01
      • 2016-01-11
      • 2011-05-31
      • 2014-06-25
      • 1970-01-01
      • 2016-08-08
      相关资源
      最近更新 更多