Conditional http auth

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


On 03/12/2010 23:00, Eugaia wrote:
> 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;
>
> }
>
It appears that auth_basic doesn't take variables, so this won't work 
anyway.

Marcus.



More information about the nginx mailing list