Welcome! Log In Create A New Profile

Advanced

Re: Blocking by user agent if ip doesn't match

May 31, 2011 03:36PM
On Tue, May 31, 2011 at 10:19:13PM +0300, Alexandr Gomoliako wrote:
> On 5/31/11, karabaja <nginx-forum@nginx.us> wrote:
> > syntax would be in nginx config or if it is even possible to match both
> > statements.
>
> It is possible and there are different ways to match two conditions. I
> like this one:
>
> geo $google {
> default 0;
> 66.0.0.0/8 1;
> }
> map $http_user_agent $googlebot {
> default 0;
> ~google $google;
> }
>
> server {
> location / {
> if ($googlebot) {
> ...
> }
> }
> }

It works since 0.9.6. I'm going to change case sensitivity like this

~Google # case sensitive
~*google # case insensitive

Expression compatible with old and new syntax (for gracefull upgrade):

~(?i)google # case insensitive

As to configuraiton it's better to use this logic:

geo $not_google {
default 1;
66.0.0.0/8 0;
}

map $http_user_agent $bots {
default 0;
~(?i)google $not_google;
"~(?i)(Purebot|Lipperhey|MaMaCaSpEr|libwww-perl|Mail.Ru|gold crawler)" 1;
}

server {
location / {
if ($bots) {
return 403;
}
}
}


--
Igor Sysoev

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Blocking by user agent if ip doesn't match

karabaja May 31, 2011 02:49PM

Re: Blocking by user agent if ip doesn't match

António P. P. Almeida May 31, 2011 03:06PM

Re: Blocking by user agent if ip doesn't match

Alexandr Gomoliako May 31, 2011 03:20PM

Re: Blocking by user agent if ip doesn't match

Igor Sysoev May 31, 2011 03:36PM

Re: Blocking by user agent if ip doesn't match

Alexandr Gomoliako May 31, 2011 04:36PM

Re: Blocking by user agent if ip doesn't match

António P. P. Almeida May 31, 2011 05:06PM

Re: Blocking by user agent if ip doesn't match

Alexandr Gomoliako May 31, 2011 05:30PM

Re: Blocking by user agent if ip doesn't match

Igor Sysoev June 01, 2011 03:26AM

Re: Blocking by user agent if ip doesn't match

Hari Hendaryanto June 01, 2011 04:48AM

Re: Blocking by user agent if ip doesn't match

Igor Sysoev June 01, 2011 04:50AM

Re: Blocking by user agent if ip doesn't match

karabaja May 31, 2011 06:01PM

Re: Blocking by user agent if ip doesn't match

António P. P. Almeida May 31, 2011 06:28PM

Re: Blocking by user agent if ip doesn't match

António P. P. Almeida May 31, 2011 06:34PM

Re: Blocking by user agent if ip doesn't match

karabaja May 31, 2011 06:44PM

Re: Blocking by user agent if ip doesn't match

António P. P. Almeida May 31, 2011 07:00PM

Re: Blocking by user agent if ip doesn't match

Igor Sysoev June 01, 2011 03:30AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 47
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready