【问题标题】:Combining Basic Authentication and LimitExcept in Apache 2.2 Virtual Host在 Apache 2.2 虚拟主机中结合基本身份验证和 LimitExcept
【发布时间】:2016-02-18 04:24:17
【问题描述】:

我正在尝试满足以下要求(在 Apache HTTPD 2.2 中):

  • 如果 HTTP 方法不是 HEAD、POST 或 GET,则不允许访问,无论以下任何情况。
  • 如果用户是内部用户,则在没有基本身份验证质询的情况下允许访问。
  • 如果用户是外部用户,则使用基本身份验证进行质询,如果他们有良好的凭据则允许进入。

这是我尝试过的众多事情之一,但我尝试过的所有事情都没有达到所有三个要求:

<Directory /path/to/wwwroot>
    Options FollowSymLinks
    AllowOverride FileInfo

    # Basic Authentication
    AuthType Basic
    AuthName "Enter your site username and password."
    AuthUserFile /path/to/stage.passwords
    AuthGroupFile /path/to/stage.groups
    Require group stageusers

    # there's more logic for this variable in the real virtual_host.
    # for this simplified example, manually set (using the following)
    # or unset (using !internal_user).
    SetEnv internal_user

    Order deny,allow
    Deny from all
    Allow from env=internal_user

    <LimitExcept HEAD POST GET>
        Deny from all
    </LimitExcept>

    Satisfy all

</Directory>

我已阅读有关 Satisfy、Limit、LimitExcept、Order 和基本身份验证的文档,但我无法将这些部分组合在一起。

有什么可行的方法来做到这一点?

【问题讨论】:

    标签: apache virtualhost basic-authentication http-method


    【解决方案1】:

    Apache 2.2 中的 AFAICT,您需要返回“满足任何”方法,然后使用 mod_rewrite 处理方法检查。这是最佳途径,因为您的方法检查是完全独立的。

    在 2.4 中,Limit/LimitExcept 被 mod_allowmethods 替换/简化,但 require 也可以直接检查方法。那里要简单得多。

    重写部分非常简单:

    RewriteEngine ON
    RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST)$
    RewriteRule .* - [F]
    

    但您需要确保它出现在每个可以访问该目录的 vhost + 主服务器中,这与其他指令不同。

    把它们放在一起

    # Only allow expected HTTP methods.
    RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST)$
    RewriteRule .* - [F]
    
    <Directory /path/to/wwwroot>
        Options FollowSymLinks
        AllowOverride FileInfo
    
        Satisfy any
    
        # Basic Authentication
        AuthType Basic
        AuthName "Enter your site username and password."
        AuthUserFile /path/to/stage.passwords
        AuthGroupFile /path/to/stage.groups
        Require group stageusers
    
        # there's more logic for this variable in the real virtual_host.
        # for this simplified example, manually set (using the following)
        # or unset (using !internal_user).
        SetEnv internal_user
    
        Order deny,allow
        Deny from all
        Allow from env=internal_user
    
    </Directory>
    

    【讨论】:

    • 直到今天我才能回到这个任务。我以前从未使用过赏金,但现在我无法奖励它并且它已从我的代表中扣除。我猜这个系统背后有逻辑(我不明白)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 2015-01-27
    • 2018-01-15
    • 1970-01-01
    • 2013-05-22
    • 2012-02-04
    • 2017-12-04
    相关资源
    最近更新 更多