【发布时间】:2015-06-28 14:47:42
【问题描述】:
好的,在新安装的 Ubuntu 14.04 上运行 Apache 2.4.7。
如果我将以下内容添加到/etc/apache2/sites-available 中的 .conf 文件中,则基本身份验证可以正常工作:
<Location /test>
AuthType Basic
AuthName ".htaccess Basic Auth Test"
AuthUserFile "/var/www/passwords/test"
Require valid-user
</Location>
但是,如果我只是在相关目录的.htaccess 文件中有以下内容:
AuthType Basic
AuthName ".htaccess Basic Auth Test"
AuthUserFile "/var/www/passwords/test"
Require valid-user
身份验证似乎被忽略了;没有提示,页面就好像它们不存在一样。目录块也是如此:
<Directory /var/www/default/test>
AuthType Basic
AuthName ".htaccess Basic Auth Test"
AuthUserFile "/var/www/passwords/test"
Require valid-user
</Directory>
所以,我检查了 .htaccess 文件是否真的被读取,它们是;添加
Options -Indexes
到.htaccess 文件确实会删除目录上的索引列表。
我打开了调试,但这并不是特别有用:
[Tue Apr 21 13:04:14.082275 2015] [authz_core:debug] [pid 8914] mod_authz_core.c(721): [client 144.32.48.10:64109] AH01625: authorization result of <RequireAny>: granted (directive limited to other methods)
[Tue Apr 21 13:04:14.082538 2015] [authz_core:debug] [pid 8914] mod_authz_core.c(721): [client 144.32.48.10:64109] AH01625: authorization result of <RequireAny>: granted (directive limited to other methods)
/etc/apache2 中的 Grep'ing 显示没有任何限制;没有其他Auth 语句,AllowOverride All 在正确的位置(如选项测试所示;他们说All,没有其他可能限制覆盖的东西)。
我觉得我一定遗漏了一些明显的东西。这是加载的模块:
root@linode:/etc/apache2# apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
filter_module (shared)
headers_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php5_module (shared)
proxy_module (shared)
proxy_http_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
substitute_module (shared)
xml2enc_module (shared)
【问题讨论】:
-
试一试。没有
":AuthUserFile /var/www/passwords/test因为我从不使用它们,这最终可能是绝对路径的问题...... -
@Croises 唉,不;我想我添加了它们以防它改变任何东西!
-
您是否尝试为每个测试更改
AuthName ".htaccess Basic Auth Test"?因为如果您为 2 个或更多目录请求相同的AuthName,浏览器只会第一次询问... -
@Croises 只是尝试了一个不同的名称,没有改变,仍然被忽略。
标签: .htaccess authentication basic-authentication apache2.4