# Combine basic auth and ip whitelisting

**URL:** <https://www.ruby-forum.com/t/combine-basic-auth-and-ip-whitelisting/218817>\
**Category:** NGINX\
**Created:** [April 12, 2012, 11:40pm UTC](https://www.ruby-forum.com/t/combine-basic-auth-and-ip-whitelisting/218817 "2012-04-12T23:40:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 12, 2012, 11:40pm UTC](https://www.ruby-forum.com/t/combine-basic-auth-and-ip-whitelisting/218817/1 "2012-04-12T23:40:36Z")

</div>

Hi,

I have set up Apache for an existing site to use either ip whitelisting  
or basic authentication. If the user’s IP is not on the IP whitelist, it  
asks him for a password. My htaccess file looks something like this:

* * *

Order deny,allow  
Deny from all  
AuthName “Restricted Area”  
AuthUserFile /path/to/passwords  
AuthType Basic  
Require valid-user  
Allow from 123.456.789.10  
Allow from 123.456.789.11  
Satisfy Any

---

<div class="post-metadata">

**Author:** ![jaynyc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jaynyc](https://www.ruby-forum.com/u/jaynyc)\
**Post date:** [April 12, 2012, 11:48pm UTC](https://www.ruby-forum.com/t/combine-basic-auth-and-ip-whitelisting/218817/2 "2012-04-12T23:48:38Z")

</div>

Hello!

On Thu, Apr 12, 2012 at 05:39:42PM -0400, jaynyc wrote:

> ## AuthUserFile /path/to/passwords AuthType Basic Require valid-user Allow from 123.456.789.10 Allow from 123.456.789.11 Satisfy Any
> 
> Is it possible to do something like this with Nginx?

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#satisfy)**
>
> This directive appeared in version 1.11.8.

location / {  
satisfy any;

```
allow 192.168.1.0/32;
deny all;

auth_basic "closed site";
auth_basic_user_file conf/htpasswd;

```

}

Maxim D.

---

<div class="post-metadata">

**Author:** ![jaynyc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jaynyc](https://www.ruby-forum.com/u/jaynyc)\
**Post date:** [April 13, 2012, 9:40am UTC](https://www.ruby-forum.com/t/combine-basic-auth-and-ip-whitelisting/218817/3 "2012-04-13T09:40:20Z")

</div>

> ## AuthUserFile /path/to/passwords AuthType Basic Require valid-user Allow from 123.456.789.10 Allow from 123.456.789.11 Satisfy Any

> Is it possible to do something like this with Nginx?

auth\_basic “Restricted Area”; # realm  
auth\_basic\_user\_file /path/to/passwords;

allow 123.456.789.10;  
allow 123.456.789.11;  
deny all;

satisfy any;

–appa

---

<div class="post-metadata">

**Author:** ![jaynyc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jaynyc](https://www.ruby-forum.com/u/jaynyc)\
**Post date:** [April 13, 2012, 5:54pm UTC](https://www.ruby-forum.com/t/combine-basic-auth-and-ip-whitelisting/218817/4 "2012-04-13T17:54:49Z")

</div>

Hi Appa and Maxim,

Thanks a lot for your help. That worked! 🙂

Regards,

- Jay

Posted at Nginx Forum:

> **[Re: combine basic auth and ip whitelisting](https://forum.nginx.org/read.php?2,225266,225314#msg-225314)**
>
> Hi, I have set up Apache for an existing site to use either ip whitelisting or basic authentication. If the user's IP is not on the IP whitelist, it asks him for a password. My htaccess file looks something like this: --------------- Order deny,allow...
