Forum: NGINX Deny ips, and pick ips from a file.

Posted by Quintin Par (Guest)
on 2012-10-11 07:56
(Received via mailing list)
Hi all,

I need to deny users by ip. I assume we need to do something like this

location / {

  # block one workstation

  deny    192.168.1.1;

  # allow anyone in 192.168.1.0/24

  allow   192.168.1.0/24;

  # drop rest of the world

  deny    all;

}

But how can I pass on the list of ips from a file? A file which will get
udated from time to time.

Can I pass the ips something like this

 deny   /tmp/iplist.txt;

Will Nginx refresh the ip list in memory if the file gets changed?

-Quintin
Posted by Anton Yuzhaninov (Guest)
on 2012-10-11 12:04
(Received via mailing list)
On 11.10.2012 09:50, Quintin Par wrote:
>    allow 192.168.1.0/24 <http://192.168.1.0/24>;
> Can I pass the ips something like this
>
>   deny   /tmp/iplist.txt;

If list of IP to block is really big, then better to use geo module 
instead
allow/deny: http://nginx.org/en/docs/http/ngx_http_geo_module.html

geo $denyed_host {
  default 1;
  include /tmp/iplist.txt;
}

...

if ($denyed_host) {
    return 403;
}

iplist.txt should contain lines like:

192.168.1.0/24 0;
192.168.1.1/32 1;

After update of /tmp/iplist.txt you should reconfigure nginx (e. g. run 
nginx -s
reload).

--
  Anton Yuzhaninov
Posted by Wolfsrudel (Guest)
on 2012-10-11 12:56
(Received via mailing list)
Posted by "António P. P. Almeida" <appa@perusio.net> (Guest)
on 2012-10-11 13:03
(Received via mailing list)
On 11 Out 2012 12h55 CEST, nginx-forum@nginx.us wrote:

> 
http://bash.cyberciti.biz/web-server/nginx-shell-s...

Also a shameless plug - I leave the server handling to be done à la
carte :)

https://github.com/perusio/nginx-spamhaus-drop

This creates a file to be used by the geo directive.

--- appa

 > Posted at Nginx Forum:
Posted by Quintin Par (Guest)
on 2012-10-13 07:22
(Received via mailing list)
Thanks Antonio. This bonus is so good.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.