different fastcgi_cache for bots and humans

Ian M. Evans ianevans at digitalhit.com
Fri Jul 12 20:22:35 UTC 2013


As mentioned before, I'm tweaking pixabay's version of handling the new
Google Image search traffic killer by making their trap URLs more
cacheable.

Img tags in the html will have ?i appended to the source and those "?i"
are removed for bots. I thought I could use nginx's httpsubmodule to strip
the ?i for bots, but I'd still like it cacheable, with one version for
humans and one for bots.

Doing some digging I came across an idea like this:

map $http_user_agent $botornot {
    default 'human';
    ~(Googlebot|Bing|other|bit|names) 'bot';
}

I'm assuming I could then use $botornot in the fastcgi_cache_key? If so,
where would I place it in my current line, which is:

fastcgi_cache_key "$scheme$request_method$host$uri?$args";

Thanks.



More information about the nginx mailing list