这是我的VirtualHost
配置:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public>
Options +FollowSymLinks
AllowOverride All
Require user user1 user2
</Directory>
<Location /error/401>
Require all granted
</Location>
ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
ErrorDocument 500 /error/500
ErrorDocument 404 /error/404
ErrorDocument 401 /error/401
</VirtualHost>
但是当我故意失败身份验证时(或直接打开/ error / 401时),我明白了:
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
Additionally, a 401 Unauthorized error was encountered while trying to use an ErrorDocument to handle the request.
我做错了什么?根据下面链接的文档,Location
应在Directory
之后处理,因此这应该有用。
http://httpd.apache.org/docs/current/sections.html#merging
修改
就这么清楚,这是有问题的部分:
Additionally, a 401 Unauthorized error was encountered while trying to use an ErrorDocument to handle the request.
答案 0 :(得分:1)
我遇到了一个非常相似的问题。关键的实际问题是,在站点的DocumentRoot级别验证失败后,无法访问位于DocumentRoot(即/ error / 401)下方的自定义错误页面,因此将发出默认的Apache错误消息。
我采用的解决方案是将html合并到ErrorDocument 401指令中。例如,
ErrorDocument 401 "INSERT MARKUP HERE"
(标记周围的引号是必不可少的)。
当然,这是一种解决方法。