Sunday, January 23, 2011

Apache: Limit the Number of Requests/Traffic per IP?

I would like to only allow one IP to use up to, say 1GB, of traffic per day, and if that limit is exceeded, all requests from that IP are then dropped until the next day. However, a more simple solution where the connection is dropped after a certain amount of requests would suffice.

Is there already some sort of module that can do this? Or perhaps I can achieve this through something like iptables?

Thanks

  • If you want a pure Apache solution bw_mod for Apache 2.0 and mod_bandwidth for Apache 1.3. They can throttle the bandwidth of your server to limit bandwidth usage.

    There is also mod_limitipconn, which prevents one user from making lots of connections to your server. mod_cband is another option, but I have never used it.

    If you don't want to mess with your Apache installation you can put a squid proxy in front of Apache. It gives you more control also over the throttling.

    However, in most cases the problem is a few large objects when you want to limit bandwidth per IP, and you want to give a sane error message when a user pulls too much data and you block him. In that case it might be easier to write a PHP script and store the access information in a temporary table in a database.

    pehrs : Have you set your robots.txt to disallow spiders?
    packs : The problem with robots.txt, is that (much like the RFC 3514) only nice robots respect it.
    pehrs : True, but you will find that the majority of the people spidering your site uses standard tools. And many of them, like wget, respects robots.txt. Robots.txt is also the correct way to inform your users you don't want them to spider.
    pehrs : Squid is probably the next step. That or simply banning them. If they bypass robots.txt I don't see any reason to service them.
    From pehrs

0 comments:

Post a Comment