Tricky Caching reverse Proxy - different User agents to be watched

Hello all

i hope somebody can help. didnt find any usefull post nor webside which
could help.

short backend story: there is a web application which generates sites,
different sites for different clients (ipod, nokia phones, normal
browser etc). its an old application running on windows, with really
poor performance.

anyway, i had the idea to use the nginx in frontend as reverse proxy
with caching, to speed up the site… and it works perfect.(caching time
only 10min, but enough to take load off the backend). the problem is:

  • when the first visitor is a normal browser, the generated page will be
    the version for browser → looks bad on the iphone/nokia phone
  • when the first visitor is iphone… it looks bad on everything else.

so … is it possible… to cache each version of the response based on
the http-agent? and to deliver when the agents xyz matchs the cached
version?

or i am asking for to much?

the websites are really small, so if a iphone has 10 different
User-Agent variables (language etc in it) it doesnt matter, it can easy
save the side 10x.

my english isnt best… if its not clear what i mean… please say so…
will try it again :slight_smile:

any help/tricks/hints would help

greets
Musa

Posted at Nginx Forum:

On Fri, May 07, 2010 at 10:18:00AM -0400, musa wrote:

so … is it possible… to cache each version of the response based on the http-agent? and to deliver when the agents xyz matchs the cached version?

or i am asking for to much?

the websites are really small, so if a iphone has 10 different User-Agent variables (language etc in it) it doesnt matter, it can easy save the side 10x.

my english isnt best… if its not clear what i mean… please say so… will try it again :slight_smile:

any help/tricks/hints would help

You may set
proxy_cache_key “$scheme$proxy_host$uri$is_args$args
$http_user_agent”;
but it will cache different responses for every browser versions.
The solution may be is to write a module that maps some configrated
regexes
to the reduced value of a variable:

 iPhone|iPod   iphone
 Nokia         nokia
 MSIE          normal
 Gecko         normal


Igor S.
http://sysoev.ru/en/

Hey Igor

thnx a lot for your answer.
it works really well. thank you.

Well, in this case (realy small page, short caching time) it doesnt
matter when it caches for each user-agent.

the idea with the module is nice, but my coding skills are not really
useable :slight_smile:

Greets
Musa

Posted at Nginx Forum:

On Mon, May 10, 2010 at 2:41 AM, musa [email protected] wrote:

Well, in this case (realy small page, short caching time) it doesnt matter when it caches for each user-agent.

The user-agent string contains a lot more than just the browser
version, unfortunately. It can also includes the versions of various
browser plug-ins, add-ons, etc., which means you are caching a
different version of each page for IE8 users with one version of .NET
or another.

For example, here’s a full user-agent string pulled from our logs:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0;
SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;
Media Center PC 6.0; InfoPath.2)

To eliminate unnecessary requests to the back-end as well as
duplicated cache entries, it might be best to use the nginx map module
to “normalize” the User-Agent to just a few values:
http://wiki.nginx.org/NginxHttpMapModule

For example (syntax not tested, just a guess based on documentation):

map $http_user_agent $shortua {
default anybrowser;
iPhone iPhone;
Blackberry bb;
IEMobile winmoble;
Windows Phone” winmobile;
}

proxy_cache_key “$scheme$proxy_host$uri$is_args$args $shortua”;


RPM