gpt4 book ai didi

Apache 2.4 : AuthType Basic and REQUEST_URI - Comparisons (with or without regular expr. ) 无法正常工作

转载 作者:行者123 更新时间:2023-12-04 19:35:35 26 4
gpt4 key购买 nike

我们在 Debian 服务器上使用 Apache 2.4.10。请求从充当平衡器(目前只有一个平衡器成员)的 Apache 代理服务器(相同的系统和版本)重定向。

对相关单个虚拟主机的访问通常通过 AuthType Basic 进行限制。只有一个包含公共(public)文档的文件夹应无需身份验证即可访问。

我测试了多种方法(新的 apache 2.4 语法)来实现这一点 - 但无论我尝试了哪种方法,我总是遇到同一个问题:与 REQUEST_URI 的任何比较都无法按预期工作 - 使用或不使用正则表达式。似乎 REQUEST_URI 在进行比较时具有无效值。

我试过了。以下替代方案:

一种)

<VirtualHost *:80>

ServerName domain.name
DocumentRoot /var/www/domain.name
DirectoryIndex index.php

<Directory "/var/www/domain.name/">

AuthType Basic
AuthName "Restricted"
AuthBasicProvider file
AuthUserFile /path/to/user/file

<RequireAny>
Require method OPTIONS
Require expr %{REQUEST_URI} =~ m#^/docs#
Require valid-user
</RequireAny>

Options +ExecCGI +FollowSymLinks
AllowOverride All

</Directory>

CustomLog "/var/log/apache2/test_log" "%t REQUEST_URI:%{REQUEST_URI}e"

</VirtualHost>

二)
<VirtualHost *:80>

ServerName domain.name
DocumentRoot /var/www/domain.name
DirectoryIndex index.php

<Directory "/var/www/domain.name/">

AuthType Basic
AuthName "Restricted"
AuthBasicProvider file
AuthUserFile /path/to/user/file

<RequireAny>
Require method OPTIONS
Require valid-user
</RequireAny>

Options +ExecCGI +FollowSymLinks
AllowOverride All

</Directory>

<LocationMatch "^/docs">
AuthType None
Require all granted
</LocationMatch>

CustomLog "/var/log/apache2/test_log" "%t REQUEST_URI:%{REQUEST_URI}e"

</VirtualHost>

C)
<VirtualHost *:80>

ServerName domain.name
DocumentRoot /var/www/domain.name
DirectoryIndex index.php

<Directory "/var/www/domain.name/">

SetEnvIf Request_URI /docs noAuth=1

AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /path/to/user/file

<RequireAny>
Require method OPTIONS
Require env noauth
Require valid-user
</RequireAny>

Options +ExecCGI +FollowSymLinks
AllowOverride All

</Directory>

CustomLog "/var/log/apache2/test_log" "%t REQUEST_URI:%{REQUEST_URI}e"

</VirtualHost>

每个替代方案似乎都停留在同一个问题上。与 REQUEST_URI 的比较失败或无法正常工作。

示例:当我将示例 A 中的第 16 行更改为
Require expr %{REQUEST_URI} =~ m#^/[a-z]#

(作为测试)然后它可以工作(无需凭据即可访问)。

当我改变 [a-z]例如 [d-i] ,它仍然有效,但是当我更改 [a-z]例如 [d-g] ,它不再起作用,并出现用户/通行证对话框。

当我相应地更改示例 B 中 LocationMatch 指令中的正则表达式时,会出现完全相同的行为。

另一个提示:

使用 <Location /docs>而不是 <LocationMatch... (参见示例 B)也不起作用。但是 <Location />作品。

和:

日志输出始终相同:

当在没有凭据的情况下授予访问权限时,REQUEST_URI 的值与所请求 URL 的路径部分相同(例如/docs)。

但是当用户/密码对话出现时,该值是一个破折号(“-”),这似乎是 apache 用于空值或不可用值的默认值。

和:

即使我直接访问服务器(没有代理)或使用例如wget 向服务器上的 localhost 发出请求。

有谁知道这里发生了什么!?...

最佳答案

我终于自己找到了解决方法。我使用版本 A) - 但使用环境变量 THE_REQUEST而不是 REQUEST_URI .幸运的是它有效!

A) 的调整版本 - 仅适用于 GET 请求:

<VirtualHost *:80>

ServerName domain.name
DocumentRoot /var/www/domain.name
DirectoryIndex index.php

<Directory "/var/www/domain.name/">

AuthType Basic
AuthName "Restricted"
AuthBasicProvider file
AuthUserFile /path/to/user/file

<RequireAny>
Require method OPTIONS
Require expr %{THE_REQUEST} =~ m#GET\s+\/docs\/[^\/]+\s+HTTP#
Require valid-user
</RequireAny>

Options +ExecCGI +FollowSymLinks
AllowOverride All

</Directory>

</VirtualHost>

关于Apache 2.4 : AuthType Basic and REQUEST_URI - Comparisons (with or without regular expr. ) 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41980102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com