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