D
D
Dmitry Sergeev2011-10-31 13:39:28
Nginx
Dmitry Sergeev, 2011-10-31 13:39:28

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 &quot;ye&quot;;<br/>
 set $b &quot;ah&quot;;<br/>
 set $r &quot;&quot;;<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 = &quot;yeah&quot;) {<br/>
 return 444;<br/>
 }<br/>
}<br/>

But such a condition works even when a regular user goes from search or VKontakte to the site, and I don’t understand why return 444 works. Maybe it’s possible to do something easier?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
YourChief, 2011-10-31
@JetMaster

read this habrahabr.ru/blogs/nginx/74135/
very likely to help you

G
gaelpa, 2011-10-31
@gaelpa

win16; !?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question