I have written a basic http referer redirector that looks something like this:
if ($http_referer ~* (google|yahoo|bing|duckduckgo)) { return 301 https://altavista.com; }
My goal is something like this
if ($http_referer ~* (google|yahoo|bing|duckduckgo)) {
add $x-forwarded-for bad_ips.txt; <-- this line is the question (x-forwarded-for because it's behind cloudflare)
return 301 https://altavista.com;
}
if ($bad_ip) {
return 301 https://altavista.com;
}
Is there any way to do this? The goal is essentially if you are referred from a website on the blacklist, I would like to add your ip to the redirect list.
Note: This does not need to be done purely in nginx; using other technologies in addition to nginx is fine so long as they are free.
Please note my site is utilizing cloudflare so rather than banning a simple IP it has to be using the x-forwarded-for address or I'm just banning cloudflare.
Thanks