D
D
Dmitry Sergeev2012-09-05 12:44:05
Nginx
Dmitry Sergeev, 2012-09-05 12:44:05

Is it possible to use regular expressions to check $http_referer?

A small flood is pouring onto the server, in the referee all sorts of crap like "5asdasd3fdas3.net", "4asdfas334.name" and so on. Is it possible to make a regular expression for this case? That is,
If ($http_referer contains more than one digit) {
return 444;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
oowl, 2012-09-05
@oowl

Regular can be used for any variable in if. If you need the regular expression itself for the “contains more than one digit” condition, then it looks something like this:

if ($http_referer ~ \d.*\d) {
  return 444;
}

E
egorinsk, 2012-09-05
@egorinsk

It's better to save the IP where strange requests come from and ban them.

V
VBart, 2012-09-05
@VBart

Instead of using the nginx.org/ru/docs/http/ngx_http_referer_module.htmlif ($http_referer module , it also allows regular expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question