Welcome! Log In Create A New Profile

Advanced

Basic auth by IP

Posted by denybell 
Basic auth by IP
February 26, 2010 02:54AM
Hello,

Is it possible to have auth_basic active for a range of ips or a specified ip only ?

[code]

geo $geo {
default 0;
127.0.0.1/32 2;
192.168.1.0/24 1;
10.1.0.0/16 1;
217.12.113.114 3;
}

server {
listen 80;
server_name mysite.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
#satisfy_any on;
# allow 193.104.211.86;
# include /root/nginx_exp/nginx/ban_list;
if ( $geo = 3 ) {
auth_basic "Restricted";
auth_basic_user_file /root/nginx_exp/nginx/my_passwords;
}
}

[/code]

This code should activate auth_basic for 217.12.113.114 only, other IPs should access the server without any authorization

but it doesn't work.... ( i know this is a very primitive code )

Any ideas ?



Edited 1 time(s). Last edit at 02/26/2010 02:55AM by denybell.
Re: Basic auth by IP
February 26, 2010 04:21AM
Hello again,

Probably I have found the solution it was simpler than I originally thought

[code]
----------------------------------------------------------------
location / {
root html;
index index.html index.htm;
satisfy_any on;
# deny all;

include /root/nginx_exp/nginx/ban_list;
allow all;

auth_basic "Restricted";
auth_basic_user_file /root/nginx_exp/nginx/my_passwords;

}
[/code]

'ban_list' is a file with the following format :
deny xxx.xxx.xxx.0/24 ;
deny xxx.xxx.xxx.0/24 ;
deny xxx.xxx.xxx.0/23 ;

So any ip from /root/nginx_exp/nginx/ban_list will see the authorization window anyone else will access the "/" without any authorization
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 120
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready