我正在尝试为我的索引文件configuration基本的身份validation,只有我的索引文件。 我已经这样configuration它:
<Files index.htm> Order allow,deny Allow from all AuthType Basic AuthName "Some Auth" AuthUserFile "C:/path/to/my/.htpasswd" Require valid-user </Files>
当我访问该页面时,按401 Authorization Required返回401 Authorization Required ,但浏览器不会提示input用户名/密码。 一些进一步的检查显示Apache没有发送WWW-Authenticate头。
GET http://myhost/ HTTP/1.1 Host: myhost Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 HTTP/1.1 401 Authorization Required Date: Tue, 21 Jun 2011 21:36:48 GMT Server: Apache/2.2.16 (Win32) Content-Length: 401 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Authorization Required</title> </head><body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (eg, bad password), or your browser doesn't understand how to supply the credentials required.</p> </body></html>
为什么Apache这样做? 我怎样才能configuration它发送适当的头?
值得注意的是,如果我把它们设置为整个目录,这个完全相同的指令集也可以正常工作。 只有当我configuration它们到一个目录索引,他们不工作。 这是我知道我的.htpasswd,这是很好的。
我在Windows上使用Apache 2.2。
另外,我发现这被列为Apache 1.3中的一个bug 。 这使我相信,这实际上是我的一个configuration问题。
我可以在Fedora下的Apache 2.2上重现这一点。 这似乎是一个错误。 解决方法是使用:
<Files ~ "(^index.htm$)|(^$)">
这是另一个类似的错误: https : //issues.apache.org/bugzilla/show_bug.cgi?id=46685
对于一个简单的例子,你的configuration看起来很好(看这个post的例子),所以我会先看看任何可能使这个非简单情况的因素,并消除它们,直到find导致问题的因素。
例如:
Apache文档有一个不错的页面,详细介绍了Directory,Files和Location的工作方式,以及一些示例,供进一步参考。
您可能需要调整您的Files指令(<Files ./index.htm>),否则它将匹配该.htaccess下的整个目录结构中的任何index.htm文件。
你发布的configuration在Debian – Apache 2.2安装上完美。 我build议尝试查看是否将其放在<Location>指令中,并在两个不同的浏览器上尝试。
我在想这个指令之间有冲突:
allow from all
和指令
require valid user
我想知道是否从configurationlogging中删除所有的允许,这可能会做你想做的事情。
顺便说一句,我会改变文件index.html到位置/index.html而不是。