假设我有一个文件list_of_naughty_ip_blocks.conf。 我可以使用include指令在我的httpd.conf中实现下面第8行的等价物吗? 如果是这样,那么正确的语法是什么? 关于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>
编辑清晰。
在include文件中只需要input“Deny from”关键字:
<Location /secret/> Order Allow,Deny Allow from all Deny from env=UnwantedRobot Include conf.d/moredeny.inc </Location>
在moredeny.inc
Deny from 192.168.1.1 Deny from 192.168.66.1 Deny from 192.168.1.1
一个'肮脏'的方式是使用sed在env=UnwantedRobot模式之后附加一行。 假设你在httpd.conf有以下内容:
<Directory "/var/www/"> Order Allow,Deny Allow from all Deny from env=UnwantedRobot </Directory>
和ip.txt文件包括:
1.2.3.4 5.6.7.8
运行以下命令:
$ while read ip; do sed -i '/env=UnwantedRobot/ a\ \tDeny\ from\ '"$ip"'' httpd.conf; done < ip.txt
你会得到结果:
<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表示编辑文件 a立场