这是我的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.