【问题标题】:Apache 2.4 Directory access control for mod_auth_formApache 2.4 mod_auth_form 的目录访问控制
【发布时间】:2015-04-03 17:41:33
【问题描述】:

我在这个简单的目录访问规则方面需要一些帮助 - 抱歉,我刚开始使用 Apache 2.4,之前没有这样做过。

我已将 Apache 2.4 配置到可以看到受保护资源登录的阶段,一旦输入用户/密码,我就可以访问受保护资源。

现在我想做以下我不知道如何完成的事情。

  1. Web 根目录设置为 /var/www
  2. /var/www/login - 任何人都可以访问,不需要身份验证,因为此文件夹包含 login.html 和 logout.html。 (我得到了这个工作)
  3. /var/www - 我的应用程序根目录中的所有其他内容只能在身份验证后访问。这是我不知道如何设置的部分。

我的虚拟主机配置看起来像这样。

    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.

我怎样才能做到这一点?

【问题讨论】:

    标签: directory apache2 mod-auth


    【解决方案1】:

    想通了。就像使用 Directory 一样简单,首先拒绝所有对根文档的访问,并且只允许有效用户。

    使用另一个目录打开对 auth 文件夹的所有访问权限。

    【讨论】:

      猜你喜欢
      • 2017-12-13
      • 2017-07-18
      • 2019-01-05
      • 2015-06-13
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 2014-12-16
      • 2019-11-03
      相关资源
      最近更新 更多