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