<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hi,<br><br>give varnish [1] a look, its probably better suited for such a scenario.<br><br><br>[1] http://www.varnish-cache.org/<br><br><br><br>> Date: Sun, 8 May 2011 03:29:31 +0400<br>> From: mdounin@mdounin.ru<br>> To: nginx@nginx.org<br>> Subject: Re: proxy caching<br>> <br>> Hello!<br>> <br>> On Sat, May 07, 2011 at 08:49:43AM -0400, bluescreen303 wrote:<br>> <br>> > Hi all,<br>> > <br>> > I would like to use nginx to cache some responses from my backends.<br>> > There are basically 2 types of responses I would like to cache.<br>> > <br>> > - public images that never expire<br>> > - private content<br>> > <br>> > The first one was easy, got that working already. Since my application<br>> > uses timestamps in the html when referring to images, changes to them<br>> > will be instantly picked up.<br>> > <br>> > The second one is way harder.<br>> > Responses can become quite large (1 upto 10Mb).<br>> > My backend application is putting etags on the responses so it can<br>> > return 304s if nothing changed.<br>> > Also, it puts a 5min max-age cache-control on it,<br>> > Lastly, responses are marked private, because they are behind http basic<br>> > authentication (handled by the backend app).<br>> > <br>> > What I would like nginx to do is the following:<br>> > It should store the first response for a certain url, using the current<br>> > http auth in the key (so it won't accidentally become publicly<br>> > available).<br>> > If a second request comes in for the same url with the same http auth<br>> > within 5 minutes: serve from cache.<br>> > If a second request comes in for the same url with the same http auth<br>> > _after_ 5 mintutes: ask backend using the if-not-modified header.<br>> > - if modified, store the new response.<br>> > - if 304 not modified, respond from cache, update cache to be valid for<br>> > 5 minutes again.<br>> > If a request comes in for the same url but with other http auth: ignore<br>> > cache and ask backend.<br>> > <br>> > The http auth stuff seems solvable by using the http auth in the<br>> > cache_key.<br>> > The other 2 things I would like to solve are:<br>> > <br>> > - I can't find clear info about nginx's handling of etag and<br>> > if-not-modified. Will it work as described above out-of-the-box?<br>> > It's especially important that nginx uses if-not-modified when querying<br>> > the backend, even if the client request itself didn't contain it.<br>> > Ofcourse if the client request did include it, it should receive a nice<br>> > 304 too.<br>> <br>> Right now nginx can't use conditional requests to refresh cache.<br>> <br>> > - The backend sends Cache-Control: private for these responses. I would<br>> > like nginx to cache them though.<br>> > Ignoring the Cache-Control header doesn't seem to work (because without<br>> > cache-control at all, caching seems disabled)<br>> > Another option might be to have the backend set cache-control to public<br>> > and have nginx set it back to private, but that sounds a bit hacky.<br>> <br>> Solution is to ignore Cache-Control header and enable caching <br>> explicitly with proxy_cache_valid directive.<br>> <br>> Maxim Dounin<br>> <br>> _______________________________________________<br>> nginx mailing list<br>> nginx@nginx.org<br>> http://nginx.org/mailman/listinfo/nginx<br>                                            </body>
</html>