Search code examples
nginxspam-prevention

How to block Referrer Spam


I am using NGINX and one of my site is suffering from referrer spam.

I followed the NGINX wiki, and I found this but after using the code, it is blocking my site. Is there any solution? I have also tried using this code but it didn't worked

if ($http_referer ~ "spamdomain1\.com|spamdomain2\.com|spamdomain3\.com")  { 
return 444;
}

I want to block the domain from where I am getting referrer hits.


Solution

  • I would use a map.

    # at the http level:
    map $http_referer $drop_referer {
        default 0;
        ~spamdomain1\.com   1;
        ~spamdomain2\.com   1;
        ~spamdomain3\.com   1;
        # ... (put these in an included file if there are many)
    }
    
    # in your server stanza:
    if ($drop_referer) {
        return 444;
    }