我需要一些关于这个简单的目录访问规则的帮助 - 抱歉,我刚刚开始使用Apache 2.4并且之前没有这样做过。
我已经将Apache 2.4配置到一个阶段,我可以看到登录受保护的资源,一旦我输入用户/通行证,我就可以访问受保护的资源。
现在我想做以下事情,我不知道如何完成这项工作。
我的vhost conf看起来像这样。
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/var/www"
ServerName auth-test.ml.com
ErrorLog "logs/test-error_log"
CustomLog "logs/test-access_log" common
<Directory "/var/www">
AuthFormProvider file
AuthType form
AuthName "Reserved Area"
Session On
SessionCookieName session path=/
require valid-user
# This is the login page
ErrorDocument 401 /login/index.html
# This is the file containing users login data
AuthUserFile /usr/local/apache2/auth/.htpasswd
</Directory>
<Directory /var/www/login>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
当我访问像http://example.com这样的应用时,我希望看到login.html页面返回但是我收到以下错误消息:
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.
我该如何做到这一点?
答案 0 :(得分:0)
想出来。就像使用Directory首先拒绝对根文档的所有访问权限并且仅允许有效用户一样简单。
使用其他目录打开对auth文件夹的所有访问权限。