In order to prevent referrer spam, my nginx.conf contains a section like this:
if ($http_referer ~* spamdomain1\.com) {
return 444;
}
if ($http_referer ~* spamdomain2\.com) {
return 444;
}
if ($http_referer ~* spamdomain3\.com) {
return 444;
}
These rules tell nginx just to close the connection if the user has one of these referrers set. Is there a more elegant way to do this? Can I define a list of these domains and then say something like, “If the referrer is in this list then return 444”?