如何在Apacheconfiguration中将目录白名单

在Wordpress中,减less服务器负载的less数有效方法之一是将单个客户端列入白名单到/wp-login.php/wp-admin/

 <Directory /wp-admin> order deny,allow deny from all allow from 10.1.1.50 allow from ...other ips... </Directory> 

但我不想编辑和重新加载Apache来改变这个列表。 在我的虚拟主机中,我想要:

 <Directory /wp-admin> RewriteEngine On RewriteMap hosts-allow txt:/var/www/html/wp/wp-admin/hosts.allow RewriteCond ${hosts-allow:%{REMOTE_ADDR}|NOT-FOUND} =NOT-FOUND [AND] RewriteCond ${hosts-allow:%{REMOTE_HOST}|NOT-FOUND} =NOT-FOUND RewriteRule ^ - [F] </Directory> 

但:

 [root@blah httpd]# service httpd reload Reloading httpd: not reloading due to configuration syntax error [FAILED] [root@blah httpd]# apachectl -S Syntax error on line 34 of /etc/httpd/sites-enabled/example.org.conf: RewriteMap not allowed here 

那么是否有一种方法可以实现这个说法,不需要RewriteMap,还是我需要编写一个新的模块?

创build.htaccess文件,并把允许的IP地址在那里。 Directory不允许RewriteMap。

尝试这个:

  RewriteMap ipslist txt:/full/path/to/iplist.txt RewriteCond %{REMOTE_ADDR} ^(.*)$ RewriteCond ${ipslist:%1|black} ^black$ [NC] RewriteRule (.*) - [F] 

你的文件应该是这样的:

 192.168.0.12 ok 127.0.0.1 ok [...]