# Am I using proxy\_cache correctly?

**URL:** <https://www.ruby-forum.com/t/am-i-using-proxy-cache-correctly/201511>\
**Category:** NGINX\
**Created:** [January 9, 2011, 6:03pm UTC](https://www.ruby-forum.com/t/am-i-using-proxy-cache-correctly/201511 "2011-01-09T18:03:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 9, 2011, 6:03pm UTC](https://www.ruby-forum.com/t/am-i-using-proxy-cache-correctly/201511/1 "2011-01-09T18:03:09Z")

</div>

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 {  
server\_name [media.domain.com](http://media.domain.com);  
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 [media.domain.com](http://media.domain.com), but we  
are using GD to perform image resizing. For instance, requests like  
this are sent through:  
[http://media.domain.com/?controllerName=image&action=get&id=4164&format=homepage\_lead](http://media.domain.com/?controllerName=image&action=get&id=4164&format=homepage_lead)

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?

Thanks!

Posted at Nginx Forum:

> **[Am I using proxy\_cache correctly?](https://forum.nginx.org/read.php?2,164842,164842#msg-164842)**
>
> 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;...
