Tricky Caching reverse Proxy - different User agents to be watched

Igor Sysoev igor at sysoev.ru
Sat May 8 01:19:32 MSD 2010


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

> 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 :)
> 
> 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 Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list