Nginx Block User Agent: различия между версиями

Материал из Webko Wiki
Перейти к навигации Перейти к поиску
(Новая страница: «You can block any http user agents with GET / POST requests that scrape your content or try to exploit software vulnerability. Use the following syntax. Edit /usr…»)
 
 
Строка 1: Строка 1:
 +
[http://forum.vestacp.com/viewtopic.php?f=28&t=8975]
 +
 
You can block any http user agents with GET / POST requests that scrape your content or try to exploit software vulnerability. Use the following syntax. Edit /usr/local/nginx/conf/nginx.conf file, enter:
 
You can block any http user agents with GET / POST requests that scrape your content or try to exploit software vulnerability. Use the following syntax. Edit /usr/local/nginx/conf/nginx.conf file, enter:
 
  # vi /usr/local/nginx/conf/nginx.conf
 
  # vi /usr/local/nginx/conf/nginx.conf

Текущая версия на 18:07, 13 августа 2015

[1]

You can block any http user agents with GET / POST requests that scrape your content or try to exploit software vulnerability. Use the following syntax. Edit /usr/local/nginx/conf/nginx.conf file, enter:

# vi /usr/local/nginx/conf/nginx.conf

In this example, block http user agent called wget:

## Block http user agent - wget ##
   if ($http_user_agent ~* (Wget) ) {
   return 403;
   }

## Block Software download user agents ##
   if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
           return 403;
   }

Save and close the file. Reload nginx web server, enter:

# service nginx reload


How do I block multiple http user agents?

Use the following syntax:


if ($http_user_agent ~ (agent1|agent2|Foo|Wget|Catall Spider|AcoiRobot) ) {
return 403;
}

Case insensitive blocking: ~* vs ~

Please note the ~* makes it case insensitive as opposed to just a ~:


### case sensitive http user agent blocking  ###
if ($http_user_agent ~ (Catall Spider|AcoiRobot) ) { 
   return 403;
}
### case insensitive http user agent blocking  ###
if ($http_user_agent ~* (foo|bar) ) {
   return 403;
}

Пример

  if ($http_user_agent ~* (AhrefsBot|MJ12bot|dobot|BLEXBot) ) {
   return 403;
  }