Conditional http auth

Eugaia ngx.eugaia at gmail.com
Sat Dec 4 00:00:21 MSK 2010


Hi,

On 03/12/2010 22:49, Michael Shadle 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;
>
> Any ideas on how to do conditional auth?
>
> auth_basic and such is not allowed under "if" ... trying to figure out
> some way to dynamically do this.
I think if you put the if() inside the server rather than inside a 
location it should work.

e.g.

server {

set $realm "enter your password";

if ($http_via ~* ".somehost.net") {

     set $realm off;
}

location / {
     auth_basic $realm;
     auth_basic_user_file /etc/nginx/confs/htpasswd.test;

}

...

Though I've not tested it.

Cheers,

Marcus.



More information about the nginx mailing list