# Howto create conditional basic authentication

**URL:** <https://www.ruby-forum.com/t/howto-create-conditional-basic-authentication/183008>\
**Category:** NGINX\
**Created:** [February 5, 2010, 11:23pm UTC](https://www.ruby-forum.com/t/howto-create-conditional-basic-authentication/183008 "2010-02-05T23:23:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![azgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@azgar](https://www.ruby-forum.com/u/azgar)\
**Post date:** [February 5, 2010, 11:23pm UTC](https://www.ruby-forum.com/t/howto-create-conditional-basic-authentication/183008/1 "2010-02-05T23:23:47Z")

</div>

Hi all,

I have an operational NGINX server with e few dozen location {}  
definitions

When a connection is made from an internal network towards the server  
the client browser gets all the pages. Now I like to add external  
access, but I need to require basic authentication. Can this be done  
without duplication of these few dozen location {} definitions or ???

Hope anybody can help me out.

---

<div class="post-metadata">

**Author:** ![azgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@azgar](https://www.ruby-forum.com/u/azgar)\
**Post date:** [February 5, 2010, 11:57pm UTC](https://www.ruby-forum.com/t/howto-create-conditional-basic-authentication/183008/2 "2010-02-05T23:57:59Z")

</div>

Hello!

On Fri, Feb 05, 2010 at 11:23:47PM +0100, Paul S. wrote:

> I have an operational NGINX server with e few dozen location {}  
> definitions
> 
> When a connection is made from an internal network towards the server  
> the client browser gets all the pages. Now I like to add external  
> access, but I need to require basic authentication. Can this be done  
> without duplication of these few dozen location {} definitions or ???

Try this at server level:

```
satisfy any;

# allow internal networks
allow 10.0.0.0/8;
deny all;

# allow authenticated users
auth_basic ...
auth_basic_user_files ...

```

Wiki has no up-to-date information about satisfy directive  
(0.6.25+), but it’s basically the same as deprecated satisfy\_any  
as described here:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Original documentation (in Russian) is here:

> **[Модуль ngx\_http\_core\_module](http://nginx.org/ru/docs/http/ngx_http_core_module.html)**

To Igor: docs lists only “location” context for satisfy directive,  
while it’s allowed at http and server level. Could you please fix  
it?

Maxim D.

---

<div class="post-metadata">

**Author:** ![azgar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@azgar](https://www.ruby-forum.com/u/azgar)\
**Post date:** [February 5, 2010, 11:59pm UTC](https://www.ruby-forum.com/t/howto-create-conditional-basic-authentication/183008/3 "2010-02-05T23:59:09Z")

</div>

On Fri, Feb 5, 2010 at 4:23 PM, Paul S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi all,
> 
> I have an operational NGINX server with e few dozen location {}  
> definitions
> 
> When a connection is made from an internal network towards the server  
> the client browser gets all the pages. Now I like to add external  
> access, but I need to require basic authentication. Can this be done  
> without duplication of these few dozen location {} definitions or ???

I think creative use of the “include” directive can eliminate the  
duplication for you. Keep the config for locations in separate files,  
and then include them as appropriate. You can also have an include for  
authentication.

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

–  
RPM
