<a href="http://www.ncache.org">www.ncache.org</a><div><br></div><div>an nginx cache module </div><div><br></div><div>maybe this can help u .<br><br><div class="gmail_quote">On Tue, Apr 7, 2009 at 5:03 PM, Payam Chychi <span dir="ltr">&lt;<a href="mailto:pchychi@gmail.com">pchychi@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">2009/4/7 Igor Sysoev &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt;:<br>
<div><div></div><div class="h5">&gt; On Tue, Apr 07, 2009 at 12:55:37AM -0700, Payam Chychi wrote:<br>
&gt;<br>
&gt;&gt; On Mon, Apr 6, 2009 at 11:03 PM, Payam Chychi &lt;<a href="mailto:pchychi@gmail.com">pchychi@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; thank you sir =) you are a king!<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; -Payam<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2009/4/6 Igor Sysoev &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt;:<br>
&gt;&gt; &gt;&gt; On Mon, Apr 06, 2009 at 10:46:24PM -0700, Payam Chychi wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; 2009/4/6 Igor Sysoev &lt;<a href="mailto:is@rambler-co.ru">is@rambler-co.ru</a>&gt;:<br>
&gt;&gt; &gt;&gt;&gt; &gt; On Mon, Apr 06, 2009 at 10:14:36PM -0700, Payam Chychi wrote:<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; Hi Guys,<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; I was hoping someone could point out a document where it can teach me<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; how to setup nginx + caching. I know that traditionally nginx did not<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; have a native caching and it required you to run ncache or cachemem in<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; order to perform caching of static content... but does nginx now allow<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; basic static file caching without the use of any other 3rd app?<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; Im trying to understand if nginx now has a native caching which would<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; allow caching of static content. I dont want to get fancy in anyway, I<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; simply want to allocate say 200mb of storage space to allow caching of<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; static content. the 200mb should be updated with the most<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; active/recently seen file request.<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; reason? im trying to allow nginx to serve the static files from disk<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; (if it has seen it previously) and not have to go back to the origin<br>
&gt;&gt; &gt;&gt;&gt; &gt;&gt; server every single time.<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt; Get the lastest nginx (0.7.50) and use<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;    proxy_cache_path  /path/to/cache  levels=1:2<br>
&gt;&gt; &gt;&gt;&gt; &gt;                      keys_zone=one:10m<br>
&gt;&gt; &gt;&gt;&gt; &gt;                      inactive=7d  max_size=200m;<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;    proxy_temp_path   /path/to/temp;  # must be on the same filesystem<br>
&gt;&gt; &gt;&gt;&gt; &gt;                                      # as cache<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;    server {<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;        location / {<br>
&gt;&gt; &gt;&gt;&gt; &gt;            proxy_pass              <a href="http://backend" target="_blank">http://backend</a>;<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;            proxy_cache             one;<br>
&gt;&gt; &gt;&gt;&gt; &gt;            proxy_cache_key         backend$request_uri;<br>
&gt;&gt; &gt;&gt;&gt; &gt;            proxy_cache_valid       200  1h;<br>
&gt;&gt; &gt;&gt;&gt; &gt;            proxy_cache_use_stale   error timeout invalid_header;<br>
&gt;&gt; &gt;&gt;&gt; &gt;        }<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt; --<br>
&gt;&gt; &gt;&gt;&gt; &gt; Igor Sysoev<br>
&gt;&gt; &gt;&gt;&gt; &gt; <a href="http://sysoev.ru/en/" target="_blank">http://sysoev.ru/en/</a><br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;&gt;  proxy_cache_path  /path/to/cache  levels=1:2<br>
&gt;&gt; &gt;&gt;&gt;                      keys_zone=one:10m<br>
&gt;&gt; &gt;&gt;&gt;                      inactive=7d  max_size=200m;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;    proxy_temp_path   /path/to/temp;  # must be on the same filesystem<br>
&gt;&gt; &gt;&gt;&gt;                                      # as cache<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;    server {<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;        location / {<br>
&gt;&gt; &gt;&gt;&gt;            proxy_pass              <a href="http://backend" target="_blank">http://backend</a>;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;            proxy_cache             one;<br>
&gt;&gt; &gt;&gt;&gt;            proxy_cache_key         backend$request_uri;<br>
&gt;&gt; &gt;&gt;&gt;            proxy_cache_valid       200  1h;<br>
&gt;&gt; &gt;&gt;&gt;            proxy_cache_use_stale   error timeout invalid_header;<br>
&gt;&gt; &gt;&gt;&gt;        }<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt;<br>
&gt;&gt; &gt;&gt;&gt; few questions:<br>
&gt;&gt; &gt;&gt;&gt; 1- what does the keys_zone used for<br>
&gt;&gt; &gt;&gt;&gt; 2- what does the &quot;200 1h&quot; in proxy_cache_valid mean<br>
&gt;&gt; &gt;&gt;&gt; 3- how is the &quot;proxy_cache_use_stale  error timeout invalid_header&quot; used?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; <a href="http://wiki.nginx.org/NginxHttpProxyModule#proxy_cache" target="_blank">http://wiki.nginx.org/NginxHttpProxyModule#proxy_cache</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; Igor Sysoev<br>
&gt;&gt; &gt;&gt; <a href="http://sysoev.ru/en/" target="_blank">http://sysoev.ru/en/</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; Payam Tarverdyan Chychi<br>
&gt;&gt; &gt; Network Security Specialist / Network Engineer<br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Igor,<br>
&gt;&gt;<br>
&gt;&gt; using the caching info  ... i get a &quot;redirect loop&quot; when trying to<br>
&gt;&gt; download  <a href="http://domain.com/images/spacer.gif" target="_blank">domain.com/images/spacer.gif</a>  when the file does not exist<br>
&gt;&gt; on the origin server ... ive also been able replicate this with YSlow<br>
&gt;&gt; for firefox<br>
&gt;&gt;<br>
&gt;&gt; When bypassing the proxy/cache and connecting directly to the origin,<br>
&gt;&gt; i get the proper 404 error<br>
&gt;&gt; any ideas?<br>
&gt;<br>
&gt; Probably you have something like<br>
&gt;<br>
&gt;       error_page  404  /404.html;<br>
&gt;       proxy_intercept_errors  on;<br>
&gt;       recursive_error_pages   on;<br>
&gt;<br>
&gt; without<br>
&gt;<br>
&gt;       location = /404.html {<br>
&gt;<br>
&gt; so the /404.html is proxied to backend again.<br>
&gt;<br>
&gt; Also you may cache 404 errors too:<br>
&gt;<br>
&gt;       proxy_cache_valid    200 1h;<br>
&gt;       proxy_cache_valid    404 5m;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Igor Sysoev<br>
&gt; <a href="http://sysoev.ru/en/" target="_blank">http://sysoev.ru/en/</a><br>
&gt;<br>
&gt;<br>
<br>
</div></div>Right on... that was the problem. fixed with adding exactly what you<br>
said... im now also caching 404<br>
<br>
thanks again<br>
<font color="#888888">-payam<br>
<br>
</font></blockquote></div><br></div>