Answer the question
In order to leave comments, you need to log in
Is it possible to use nginx to cut off requests to the site with the wrong user_agent && wrong referrer?
Imagine an http flood. There are requests like:
"POST /registration HTTP/1.1" 200 11973 " www.nigma.ru/ " "Yandex/1.03.000 (compatible; Win16; M)"
"POST /registration HTTP/1.1" 200 11973 " www.mail .ru/ " "Mediapartners-Google"
"GET /registration HTTP/1.1" 200 11973 " www.yahoo.com/ " "Yandex/1.01.001 (compatible; Win16; P)"
"POST /registration HTTP/1.1" 200 11973 " www.mail.ru/ " "Yandex/2.01.000 (compatible; Win16; Dyatel; Z)"
That is, it is clear that the agent and referrer are incorrect. But I don’t want to filter by only one attribute, since a Yandex bot is needed, and there can be transitions from these referrals. There is no "double" condition in nginx, so I tried to do this:
location / {<br/>
set $a "ye";<br/>
set $b "ah";<br/>
set $r "";<br/>
<br/>
if ($http_referer ~* (vkontakte|porn|upyachka|nigma|mail|yahoo)) {<br/>
set $r $r$a;<br/>
}<br/>
<br/>
if ($http_user_agent ~* (YaDirectBot|Yandex|msnbot|Rambler|Google|Yahoo|Mail)) {<br/>
set $r $r$b;<br/>
}<br/>
<br/>
if ($r = "yeah") {<br/>
return 444;<br/>
}<br/>
}<br/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question