Cache by mime type
Francis Daly
francis at daoine.org
Sun Jul 22 08:09:03 UTC 2012
On Fri, Jul 20, 2012 at 02:45:44PM -0400, burn wrote:
Hi there,
> with "proxy_no_cache $no_proxy;", there are css files in cache again.
I think the issue is with using both proxy_no_cache and proxy_cache_bypass
with the same $no_proxy variable.
(I think there was a bug related to this in the past -- something about
if you didn't use them with the same variable, bad things could happen.)
proxy_cache_bypass takes effect before the upstream is
contacted, so at that point $no_proxy is set based on an empty
$upstream_http_content_type. Later on, when proxy_no_cache is considered,
$no_proxy already has a value so that is used.
The following config seems to work for me:
===
http {
map $upstream_http_content_type $no_proxy {
default proxy;
~*^image/ 0;
}
proxy_cache_path proxy_cache keys_zone=images:1m inactive=1m;
server {
location / {
proxy_pass http://127.0.0.1:10080/;
proxy_no_cache $no_proxy;
proxy_cache_bypass 0;
proxy_cache images;
}
}
}
===
I can run the two commands
curl -i http://localhost:8000/a.png
curl -i http://localhost:8000/a.txt
and I see exactly one file in my proxy_cache directory. (And the error
log says what is going on.)
And then I can run the commands again, and from the Expires header,
I can see that the txt file came from upstream, and the png file came
from cache.
(I use the proxy_cache_bypass line just to hush a warning (in 1.2.1). I
have *not* tested this for the partly-remembered bug mentioned above.)
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list