我正在尝试满足以下要求(在Apache HTTPD 2.2中):
这是我尝试过的很多事情之一,但我尝试的所有事情都没有达到所有这三项要求:
<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>
我已阅读有关满足,限制,限制,订单和基本身份验证的文档,但我无法将各个部分组合在一起。
这样做的可行方法是什么?
答案 0 :(得分:3)
Apache 2.2中的AFAICT你需要回到'#34;满足任何&#34;然后使用mod_rewrite处理方法检查。这是最好的路线,因为您的方法检查是完全独立的。
在2.4中,mod_allowmethods替换/简化了Limit / LimitExcept,但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>