Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let's say I have a file list_of_naughty_ip_blocks.conf. Can I use the include directive to achieve the equivalent of line 8 below in my httpd.conf? If so, what is the proper syntax? Anything to note about the formatting & syntax of list_of_naughty_ip_blocks.conf?

SetEnvIfNoCase User-Agent "FNetwork" UnwantedRobot
SetEnvIfNoCase User-Agent "NG 1.x" UnwantedRobot
SetEnvIfNoCase User-Agent "larbin" UnwantedRobot

<Directory "/var/www/">
    Order Allow,Deny
    Allow from all
    Deny from env=UnwantedRobot
    Deny from "list_of_naughty_ip_blocks.conf"
</Directory>

Edited for clarity.

share|improve this question
add comment

3 Answers

Just have the "Deny from" keyphrase in the include file:

<Location /secret/>
  Order Allow,Deny
  Allow from all
  Deny from env=UnwantedRobot
  Include conf.d/moredeny.inc
</Location>

In moredeny.inc

Deny from 192.168.1.1
Deny from 192.168.66.1
Deny from 192.168.1.1
share|improve this answer
add comment

http://httpd.apache.org/docs/2.0/mod/core.html#include

share|improve this answer
    
Yes, I read that but it didn't directly answer my question, which is about the syntax. I take it you think what I proposed will work just fine? –  Ferdinand.Bardamu Sep 13 '11 at 8:32
add comment

A 'dirty' way is use sed to append a line after env=UnwantedRobot pattern. Assuming that you have the following in httpd.conf:

<Directory "/var/www/">
    Order Allow,Deny
    Allow from all
    Deny from env=UnwantedRobot
</Directory>

and the ip.txt file includes:

1.2.3.4
5.6.7.8

run the following command:

$ while read ip; do sed -i '/env=UnwantedRobot/ a\ 
                    \tDeny\ from\ '"$ip"'' httpd.conf; done < ip.txt

you will get the results:

<Directory "/var/www/">
    Order Allow,Deny
    Allow from all
    Deny from env=UnwantedRobot
    Deny from 5.6.7.8
    Deny from 1.2.3.4
</Directory>
  • -i means edit file in place
  • a stand for append
share|improve this answer
    
I think you could just include a file containing all the Deny from a.b.c.d after the Deny from env=UnwantedRobot –  Iñigo Sep 13 '11 at 9:33
    
How do you do? Include directive only allows inclusion of configuration files. –  quanta Sep 13 '11 at 9:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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