Basic Auth only for external IPs and not localhost or LAN networks

Maxim Dounin mdounin at
Wed Feb 15 09:09:32 UTC 2012


On Wed, Feb 15, 2012 at 10:03:13AM +0530, Quintin Par wrote:

> Hi all,
> I have a location directive with basic auth in it.
>         location / {
>                    auth_basic "Admin Login";
>                    auth_basic_user_file /etc/nginx/.htpasswd;
> How do I specify a rule such that the basic auth is applied only to
> external IPs and not to 127.0.0.x, 192.0.x & 10.0.x?

Use "satisfy any", see

    location / {
        satisfy any;

        auth_basic "Admin Login";
        auth_basic_user_file /etc/nginx/.htpasswd;

        deny all;

Just a side note: the "192.0.x" should probably be "192.168.x" 
instead, but you should get the idea anyway.

Maxim Dounin

More information about the nginx mailing list