So far I have only been able to block ip address on a per host basis, I would like to block ip addresses for all hosts in apache.

I've tried various combinations of

<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
deny from aa.bb.cc.dd
deny from ee.ff.gg.hh

Directory,Location etc... however all of the options I have tried either don't do anything or they cause other .htaccess files to be ignored resulting in private areas of my site to be wide open.

  • 1
    apache can but is not made to block ip, you should use firewall, most of the time allow from ip is used to securised an access to administration or thing like that. – Froggiz Nov 5 '15 at 23:22

This seems related to this: Apache httpd: How can I Deny from all, Allow from subnet, but Deny from IP within that subnet?

At first you're using a Directory section, which is related to tilesystem objects as opposed to URL paths, which is Location.

Then, if you can, use only .htaccess or httpd.conf, both can get confusing (And beware of AllowOverride, All, means that everything you put in your httpd.conf can be modified by .htaccess rules)

Then, as for Froggiz's comment, for blocking based on ip/subnet a firewall is more efficient, packets dont even reach Apache.

  • i went with "fail2ban" to ban with iptables and now I can even automated the banning procedure. – user3338098 Nov 6 '15 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.