# Auth\_basic from if condition?

**URL:** <https://www.ruby-forum.com/t/auth-basic-from-if-condition/120683>\
**Category:** NGINX\
**Created:** [November 19, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/auth-basic-from-if-condition/120683 "2007-11-19T19:37:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@Sergey](https://www.ruby-forum.com/u/Sergey)\
**Post date:** [November 19, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/auth-basic-from-if-condition/120683/1 "2007-11-19T19:37:10Z")

</div>

I seem to have discovered that something that I thought was possible  
might  
actually not be so.

I have a scenario where I would like users from specific IP ranges to  
have to go  
through the authentication procedure and others not to.

I thought for sure this would work:  
if ( $remote\_addr != range ) {  
auth\_basic “bla”;  
auth\_basic\_user\_file users.conf;  
}

However, I’m discovering that if you do a test of this config that nginx  
does  
not like the auth\_basic directive in the if condition. Is this the  
correct  
behaviour? Is there a way around it? Is there some way to emulate what I  
want?

---

<div class="post-metadata">

**Author:** ![Sergey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@Sergey](https://www.ruby-forum.com/u/Sergey)\
**Post date:** [November 19, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/auth-basic-from-if-condition/120683/2 "2007-11-19T19:55:19Z")

</div>

On Mon, Nov 19, 2007 at 06:23:40PM +0000, Sergey wrote:

> }
> 
> However, I’m discovering that if you do a test of this config that nginx does  
> not like the auth\_basic directive in the if condition. Is this the correct  
> behaviour?

Yes.

> Is there a way around it? Is there some way to emulate what I want?

location / {  
satisfy\_any on;

```
allow 192.168.1.0/32;
deny all;

auth_basic "bla";
auth_basic_user_file users.conf;

```

}
