Search code examples
nginxspam-preventionreferrer-spam

Nginx block from referrer


I need block all http connections, who have referrer click2dad.net. I write in mysite.conf:

 location / {
            valid_referers ~.*http://click2dad\.net.*;
            if ($invalid_referer = ''){
                    return 403;
            }
            try_files       $uri    $uri/   /index.php?$args;
    }

But i still see in nginx logs:

HTTP/1.1" 200 26984 "http://click2dad.net/view/VUhfCE4ugTsb0SoKerhgMvPXcmXszU" 

200, not 403

As it is correct to block all clients from the click2dad.net ?


Solution

  • It should be noted that an expression will be matched against the text starting after the “http://” or “https://” http://nginx.org/en/docs/http/ngx_http_referer_module.html

    Correct config:

     location / {
                valid_referers click2dad.net*;
                if ($invalid_referer = ''){
                        return 403;
                }
                try_files       $uri    $uri/   /index.php?$args;
        }