如何使用Nginx阻止推荐垃圾邮件?

我在Nginx服务器下运行两个mongrels。我不断收到不存在文件的请求。 IP地址经常更改,但引用URL保持不变。我想解决这个问题。     
已邀请:
https://calomel.org/nginx.html 阻止大多数“推荐人垃圾邮件” - “更多的是烦恼而不是问题” nginx.conf
    ## Deny certain Referers (case insensitive)
    ## The ~* makes it case insensitive as opposed to just a ~
 if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|organic|poker|porn|poweroversoftware|sex|teen|video|webcam|zippo))
    {  return 403;   }
    
随着列表变长,使用Nginx映射模块会更高效,更易于管理。 把它放在你的http {}块中:
map $http_referer $bad_referer {
    hostnames;

    default                           0;

    # Put regexes for undesired referers here
    "~social-buttons.com"             1;
    "~semalt.com"                     1;
    "~kambasoft.com"                  1;
    "~savetubevideo.com"              1;
    "~descargar-musica-gratis.net"    1;
    "~7makemoneyonline.com"           1;
    "~baixar-musicas-gratis.com"      1;
    "~iloveitaly.com"                 1;
    "~ilovevitaly.ru"                 1;
    "~fbdownloader.com"               1;
    "~econom.co"                      1;
    "~buttons-for-website.com"        1;
    "~buttons-for-your-website.com"   1;
    "~srecorder.co"                   1;
    "~darodar.com"                    1;
    "~priceg.com"                     1;
    "~blackhatworth.com"              1;
    "~adviceforum.info"               1;
    "~hulfingtonpost.com"             1;
    "~best-seo-solution.com"          1;
    "~googlsucks.com"                 1;
    "~theguardlan.com"                1;
    "~i-x.wiki"                       1;
    "~buy-cheap-online.info"          1;
    "~Get-Free-Traffic-Now.com"       1;
}
把它放在你的服务器{}块中:
if ($bad_referer) { 
    return 444; # emtpy response
}
它对我有用。 来自http://fadeit.dk/blog/post/nginx-referer-spam-blacklist     
在我需要根据行为阻止人员而不是防火墙可以自行解决的其他任意规则之前,我一直处于类似的情况。 我解决问题的方法是让我的逻辑(在你的情况下是Rails)做阻塞...但是很长一段时间: 让您的逻辑将块列表维护为新行分隔的纯文本文件。 以root身份创建bash(或其他)脚本以读取此文件,并将其侦听器添加到防火墙的阻止列表中 创建一个cron作业,再次以root身份调用脚本 我这样做的原因(而不仅仅是给Django权限来改变防火墙配置)就是:安全性。如果我的应用程序被黑了,我不希望它伤害其他任何东西。 bash脚本是这样的:
exec < /path/to/my/djago-maintained/block-list
while read line
do

    iptables -A INPUT --source $line/32 -j DROP

done
    
我创建了用于检查黑名单中的传入IP的模块https://github.com/oneumyvakin/ngx_http_blacklist_lookup_module 它使用来自projecthoneypot.org,blocklist.de和uceprotect.net的黑名单     

要回复问题请先登录注册