为什么在 apache2 中不允许

hjp*_*r92 7 .htaccess httpd.conf apache-2.2

我的httpd.conf文件中有以下内容:

<Directory "/www">
    Options Indexes FollowSymLinks
    AllowOverride AuthConfig FileInfo Options=Indexes,Limit
    Order allow,deny
    Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)

接下来,我有一个ChatLogs位于服务器根目录下的目录,其.htaccess文件定义如下:

Allow from all
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /www/.htpasswd
AuthGroupFile /dev/null
Require valid-user
Run Code Online (Sandbox Code Playgroud)

当我尝试访问该目录时,在服务器日志中出现 500 服务器错误(10.109.1.92是我的内网 IP):

[alert] [client 10.109.1.92] /www/ChatLogs/.htaccess: allow not allowed here
Run Code Online (Sandbox Code Playgroud)

我知道这是因为.htaccess文件中的以下语句:

Allow from all
Run Code Online (Sandbox Code Playgroud)

但是有人可以解释为什么Allow不允许该指令吗?我想稍后限制对某些 IP 地址范围的访问;并且希望它可以放置在单个目录中而不是将它们设置在httpd.conf文件中。

Jen*_*y D 6

因为你在 Limit 之前有一个逗号。这使得 apache 将其解析为选项的一部分而不是单独的覆盖。可以这样想:

AllowOverride 
               AuthConfig
               FileInfo 
               Options=Indexes,Limit
Run Code Online (Sandbox Code Playgroud)

你想要的是

AllowOverride AuthConfig FileInfo Limit Options=Indexes
Run Code Online (Sandbox Code Playgroud)

Apache 核心文档中有更多信息。