Conditional http auth
agentzh
agentzh at gmail.com
Sat Dec 4 14:18:18 MSK 2010
On Sat, Dec 4, 2010 at 4:49 AM, Michael Shadle <mike503 at gmail.com> wrote:
> Got this idea off IRC, but it looks like variables don't expand:
>
> set $realm "enter your password";
>
> if ($http_via ~* ".somehost.net") {
> set $realm off;
> }
>
> auth_basic $realm;
> auth_basic_user_file /etc/nginx/confs/htpasswd.test;
>
With the ngx_lua [1] module enabled, it's trivial:
set_by_lua $realm '
if string.match(ngx.var.http_via, ".somehost.net") then
return "off"
else
return "enter your password"
end';
auth_basic $realm;
auth_basic_user_file /etc/nginx/confs/htpasswd.test;
This should have great performance even if you're using Lua ;)
Cheers,
-agentzh
[1] https://github.com/chaoslawful/lua-nginx-module/issues/#issue/8
More information about the nginx
mailing list