无法通过“localhost”使用 mod_status

无法通过“localhost”使用 mod_status

我已经启用mod_status我自己在 Windows 10 开发环境中使用 Apache/2.4.6 时:

<Location /server-status>
    SetHandler server-status
    Require host localhost
    Require host example
    Require host example.com
    Require ip 127.0.0.1
</Location>

exampleexample.com代表我的 Windows Active Directory 主机名。)我还使用基于名称的虚拟主机,并且我有一个大致如下所示的默认主机:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/Sites/Default/htdocs"
    FallBackResource /index.php

    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common

    <Directory "C:/Sites/Default/htdocs">
        Require all granted
        AllowOverride All
        Options -Indexes
    </Directory>
</VirtualHost>

... 并且运行正常:任何未明确配置的主机名或 IP 地址都会显示我的 PHP 驱动的网站不存在错误页面,包括http://localhost/

我可以通过任何托管站点或 IP 地址成功访问服务器信息:

http://some.other.site.example.org/server-status
http://127.0.0.1/server-status

但是,使用localhost主机名会触发 403 Forbidden 状态代码:

http://localhost/server-status
AH01753: access check of 'localhost' to /server-status failed, reason: unable to get the remote host name
AH01753: access check of 'example' to /server-status failed, reason: unable to get the remote host name
AH01753: access check of 'example.com' to /server-status failed, reason: unable to get the remote host name
AH01630: client denied by server configuration: C:/Sites/Default/htdocs/server-status

我尝试localhostServerName我的默认虚拟主机的指令中删除,但仍然得到禁止

什么原因导致localhost异常?

答案1

我认为本地主机的语法应该是:

Require local

这可能不需要输入本地主机 IP 地址。此功能由mod_authz_host

答案2

localhost正在解析为 IPv6 地址,所以我需要添加以下内容:

Require ip ::1

相关内容