How to block referral spam using Nginx?

后端 未结 4 1392
甜味超标
甜味超标 2021-02-01 10:01

I\'m running two mongrels under an Nginx server. I keep getting requests for a nonexistent file. The IP addresses change frequently but the referring URL stays the same. I\'d

4条回答
  •  北海茫月
    2021-02-01 10:35

    Using Nginx map module is a a bit more efficient and easier to manage as the list gets long.

    Put this in your http {} block :

    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;
    }
    

    Put this in your server {} block:

    if ($bad_referer) { 
        return 444; # emtpy response
    }
    

    It worked for me.

    Got this from http://fadeit.dk/blog/post/nginx-referer-spam-blacklist

提交回复
热议问题