# Dynamically block ips?

**URL:** <https://www.ruby-forum.com/t/dynamically-block-ips/209961>\
**Category:** NGINX\
**Created:** [July 27, 2011, 10:35am UTC](https://www.ruby-forum.com/t/dynamically-block-ips/209961 "2011-07-27T10:35:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [July 27, 2011, 10:35am UTC](https://www.ruby-forum.com/t/dynamically-block-ips/209961/1 "2011-07-27T10:35:14Z")

</div>

Hi list,

I have a problem;  
all my website code has been “copied”; those that took it has launched  
it pretty much the same; just changed the texts and the color scheme.

That in itself is annoying, but the main problem is that they several  
times per day scrape my site for the content  
and copy that over to their website.

They do it from a dial up connection, so the ip changes reguarly,  
however I have found ways to detect them (login names etc).

What I would like to do is to block their IP:s instantly, my thinking so  
far is:  
detect them in my php scripts,  
write their IP to nginx blocked-ips config file,  
and tell nginx to reload the config files.

However, since my web scripts is not running as root, it cannot  
restart nginx. (obviously)

The only solution I can come up with is to have a cron job that runs  
every 5 minutes, check the datestamp on the blocked\_ips file,  
and if it was modified, it will tell nginx to reload the config file.  
This is however sub-optimal, since I think that will give them enough  
time window to get what they want from my site.

So, in short, my question:  
any ideas how to trigger nginx to reload config files from a php script?  
E.g. is there something that the nginx can check reguarly (the  
existence of a file or something), and upon that take action to reload  
its config files?

Any suggestions for a different solution is also much appreciated,

RJ

---

<div class="post-metadata">

**Author:** ![Ronald\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/eb8c5e/32.png) [@Ronald\_Johnson](https://www.ruby-forum.com/u/Ronald_Johnson)\
**Post date:** [July 27, 2011, 10:39am UTC](https://www.ruby-forum.com/t/dynamically-block-ips/209961/2 "2011-07-27T10:39:34Z")

</div>

On 07/27/11 09:34, Ronald Johnson wrote:

> What I would like to do is to block their IP:s instantly, my thinking so far is:  
> detect them in my php scripts,  
> write their IP to nginx blocked-ips config file,  
> and tell nginx to reload the config files.

Have a look at fail2ban ([http://www.fail2ban.org/](http://www.fail2ban.org/)).

Typically it monitors log files and responds by changing iptables rules.

Dick

---

<div class="post-metadata">

**Author:** ![Ronald\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/eb8c5e/32.png) [@Ronald\_Johnson](https://www.ruby-forum.com/u/Ronald_Johnson)\
**Post date:** [July 27, 2011, 10:55am UTC](https://www.ruby-forum.com/t/dynamically-block-ips/209961/3 "2011-07-27T10:55:43Z")

</div>

You should be able to use incron instead of cron to reload your config  
file straightaway.

On Wed, 27 Jul 2011 09:34:08 +0100, Ronald Johnson  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> They do it from a dial up connection, so the ip changes reguarly,
> 
> its config files?
> 
> Any suggestions for a different solution is also much appreciated,
> 
> RJ
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Using Opera’s revolutionary e-mail client: [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![Ronald\_Johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/eb8c5e/32.png) [@Ronald\_Johnson](https://www.ruby-forum.com/u/Ronald_Johnson)\
**Post date:** [July 27, 2011, 6:39pm UTC](https://www.ruby-forum.com/t/dynamically-block-ips/209961/4 "2011-07-27T18:39:07Z")

</div>

On 27 Jul 2011, at 09:34, Ronald Johnson wrote:

> its config files?
> 
> Any suggestions for a different solution is also much appreciated,

You could use Beanstalkd (with Pheanstalk) to create PHP workers that do  
run as root. Then you can create a new “job” in the queue, which gets  
handled asynchronously by the Pheanstalk workers in the background..
