# Deny ips, and pick ips from a file

**URL:** <https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617>\
**Category:** NGINX\
**Created:** [October 11, 2012, 7:56am UTC](https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617 "2012-10-11T07:56:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 11, 2012, 7:56am UTC](https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617/1 "2012-10-11T07:56:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 11, 2012, 12:04pm UTC](https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617/2 "2012-10-11T12:04:05Z")

</div>

On 11.10.2012 09:50, Quintin P. wrote:

> allow 192.168.1.0/24 [http://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: [Module ngx\_http\_geo\_module](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 Y.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 11, 2012, 12:56pm UTC](https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617/3 "2012-10-11T12:56:06Z")

</div>

[http://bash.cyberciti.biz/web-server/nginx-shell-script-to-block-spamhaus-lasso-drop-spam-ip-address/](http://bash.cyberciti.biz/web-server/nginx-shell-script-to-block-spamhaus-lasso-drop-spam-ip-address/)

Posted at Nginx Forum:

> **[Re: Deny ips, and pick ips from a file.](https://forum.nginx.org/read.php?2,231617,231642#msg-231642)**
>
> 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; # dro

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 13, 2012, 7:22am UTC](https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617/4 "2012-10-13T07:22:36Z")

</div>

Thanks Antonio. This bonus is so good.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 11, 2012, 1:03pm UTC](https://www.ruby-forum.com/t/deny-ips-and-pick-ips-from-a-file/223617/5 "2012-10-11T13:03:07Z")

</div>

On 11 Out 2012 12h55 CEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

> **[Nginx Shell Script To Block Spamhaus Lasso Drop Spam IP Address](https://bash.cyberciti.biz/web-server/nginx-shell-script-to-block-spamhaus-lasso-drop-spam-ip-address/)**
>
> A Nginx Shell Script To Block Spamhaus Lasso Drop Spam IP Address. Run this script once a day and drop all spam network IP with http 403 error.

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

> **[GitHub - perusio/nginx-spamhaus-drop: A shell script that creates a Nginx configuration...](https://github.com/perusio/nginx-spamhaus-drop)**
>
> A shell script that creates a Nginx configuration for using Spamhaus DROP lists

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

— appa

> Posted at Nginx Forum:
