如果触摸特定文件,如何阻止IP

时间:2012-06-29 06:49:13

标签: apache nginx ip

我有一个wordpress网站,即使我正在使用disqus,我也会不断收到很多垃圾邮件。记录访问wp-comments-post.php并永久阻止它们(或立即阻止无记录)的所有IP的好方法是什么?删除/重命名文件可能是一个解决方案,但我想阻止他们,所以他们不会回来。我正在使用nginx前面的apache作为反向代理。我想通过nginx / iptables这样做,所以它不再需要达到apache了。

3 个答案:

答案 0 :(得分:1)

你可以使用.htaccess文件

来做到这一点
order allow,deny
deny from 192.168.44.201
deny from 224.39.163.12
deny from 172.16.7.92
allow from all

或阻止范围

order allow,deny
deny from 192.168.
deny from 10.0.0.
allow from all

甚至是ISP

order allow,deny
deny from some-evil-isp.com
deny from subdomain.another-evil-isp.com
allow from all

将htaccess文件放在包含您的文件的目录中

答案 1 :(得分:1)

我使用lua模块阻止这些类型的用户,但它有点涉及。

您可以通过将以下位置块放在处理您的php的位置块之上或之内来禁止访问该文件:

location ~* wp-comments-post\.php {
    return 403;
}
location ~* .+\.php {
    # PHP handling config
}

location ~* .+\.php {
    location ~* wp-comments-post\.php {
        return 403;
    }
    # PHP handling config for others
}

答案 2 :(得分:0)

location ~* wp-comments-post\.php {
       deny all;
}