nginx simple caching solutions
António P. P. Almeida
appa at perusio.net
Sat Aug 18 23:42:54 UTC 2012
On 18 Ago 2012 07h10 CEST, ianevans at digitalhit.com wrote:
> Just an update on my situation...
>
> I installed the fastcgi caching as per the suggestions in this
> thread. Using the add_header X-My-Cache $upstream_cache_status;
> line I'm able to confirm by the headers if I'm getting cache hits or
> misses.
>
> I've also got a small handful of directories that I don't want
> cached and as per the thread, they're marked:
>
> map $uri $no_cache_dirs {
> default 0;
> /dir1 1;
> /dir2 1;
> /dir3 1;
> /dir4 1;
> /dir5 1;
> }
>
> In my fastcgi.conf there are the following lines added for the
> caching:
>
> fastcgi_cache MYCACHE; fastcgi_keep_conn on; fastcgi_cache_bypass
> $no_cache $no_cache_dirs; fastcgi_no_cache $no_cache $no_cache_dirs;
> fastcgi_cache_valid 200 301 5m; fastcgi_cache_valid 302 5m;
> fastcgi_cache_valid 404 1m; fastcgi_cache_use_stale error timeout
> invalid_header updating http_500; fastcgi_ignore_headers
> Cache-Control Expires; expires epoch; fastcgi_cache_lock on;
>
> Did a test on some of the no cache dirs (including a wordpress blog)
> and the pages in them were still getting cached. Any ideas why?
Yes, probably you need a regex based map:
So use:
map $uri $no_cache_dirs {
default 0;
~^/(?:dir1|dir2|dir3|dir4|dir5) 1;
}
instead.
--- appa
More information about the nginx
mailing list