restrict by IP for some users

Francis Daly francis at daoine.org
Thu Feb 6 00:07:17 UTC 2014


On Wed, Feb 05, 2014 at 02:49:46PM -0800, Grant wrote:

Hi there,

> I'd like to restrict access to a server block to authenticated users.
> Some of the users should be able to access it from any IP and some of
> the users should be blocked unless they are coming from a particular
> IP.  How is this done in nginx?

Perhaps something along these lines?

User "a" must come from an address listed in "geo $goodip".
Other users may come from anywhere.

===
map $remote_user $userip {
 default 1;
 a $goodip;
}

geo $goodip {
 default 0;
 127.0.0.0/24 1;
}

server {
 auth_basic "This Site";
 auth_basic_user_file htpasswd;
 if ($userip = 0) {
  return 403;
 }
}
===

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list