Am I using proxy_cache correctly?

daveyfx nginx-forum at
Sun Jan 9 20:01:00 MSK 2011

Hi all,

I'm trying to make sure that I have my disk caching set up properly for
a specific subdomain under nginx.  Here's what I have in my nginx.conf:

    proxy_cache_path /opt/nstein/cache levels=1:2 keys_zone=CACHE:100m
inactive=10m max_size=1g;
    proxy_temp_path  /opt/nstein/cache/tmp;

And here's what I have in my site config file:

server {
    access_log off;

    location / {
        proxy_pass      http://nstein_mm-rest_cluster;
        proxy_cache     CACHE;
        proxy_cache_valid       200 10;
        proxy_cache_valid       404 1m;
        proxy_cache_key "$host$request_uri";
        proxy_cache_use_stale   error timeout invalid_header;;

Basically it's image requests that come through, but we
are using GD to perform image resizing.  For instance, requests like
this are sent through:

I can see the image binary data in my /opt/nstein/cache directory and
nginx does seem to be serving from cache correctly.  What's odd to me is
that if I run ab (Apache benchmark) against the above URL, I'll still
see *some* of the requests passed on to the back end Apache server,
however most of the time the request is served from cache.

Is there a reason that some of the requests are still passed to back
end?  Why is it that not all are served from cache?


Posted at Nginx Forum:,164842,164842#msg-164842

More information about the nginx mailing list