我想要实现的目标:
到目前为止我尝试了什么:
SetEnvIfNoCase Host development\.foobar\.tld authRequired
<RequireAny>
<RequireAll>
Require all granted
Require not ip 1.2.3.4
</RequireAll>
<RequireAny>
<RequireAll>
Require all granted
Require not env authRequired
</RequireAll>
AuthType Basic
AuthName "Development"
AuthUserFile /path/to/.htpasswd
Require valid-user
</RequireAny>
</RequireAny>
我现在的问题是忽略IP块。我不知道如何正确嵌套Require指令。
答案 0 :(得分:0)
我有类似的设置,但我没有使用基于密码的身份验证。但是,我认为这种方法也适合你。
您需要做的是将IP检查的结果存储在变量中以备将来使用 下面的代码未经测试,但我认为它会起作用:
SetEnvIf X-Forwarded-For "^1\.2\.3\.4" reject-access
<If "%{HTTP_HOST} =~ /development\.foobar\.tld$/">
AuthType Basic
AuthName "Development"
AuthUserFile /path/to/.htpasswd
<RequireAll>
Require not env reject-access
Require valid-user
</RequireAll>
</If>
<Else>
<RequireAll>
Require not env reject-access
</RequireAll>
</Else>