block bot on uri with query_string

Jonathan Matthews contact at jpluscplusm.com
Sun Jul 28 12:50:28 UTC 2013


On 28 Jul 2013 10:08, "edogawaconan" <me at myconan.net> wrote:
>
> On Sun, Jul 28, 2013 at 11:55 AM, ron ramos <nhadie at gmail.com> wrote:
> > Hi All,
> >
> > Been trying to block bots from accessing a URI that has a query_string
> > "action=get_it", i tried below
> >
> >
> >         location ~* \?(action=get_it)$ {
> >
> >                 if ( $http_user_agent ~
> > (crawl|Googlebot|Slurp|spider|bingbot|tracker|click|parser|spider)) {
> >
> >                         return 404;
> >
> >                         break;
> >
> >                 }
> >
> >          }
> >
> > i just learned that location does not match query string, if i do the
is_arg
> > i cant do nested if, anyone able to do this before?
> >
> > TIA.
> >
>
> I don't remember the exact syntax but something like this should work:
>
> if ($arg_action = get_it) { set $no_bot 1; }
> if ($http_user_agent ~ <keys>) { set $is_bot 1; }
> if ($no_bot$is_bot = 11) { return 404; }

I would personally use a map{} which examined both variables and then a
single if() to take action based on the map's result.

I'd be interested in any official comment from nginx staff about the
relative merits of these approaches ...

J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130728/6480b9c5/attachment.html>


More information about the nginx mailing list