# Simple question about proxy cache

**URL:** <https://www.ruby-forum.com/t/simple-question-about-proxy-cache/227488>\
**Category:** NGINX\
**Created:** [March 17, 2013, 10:17pm UTC](https://www.ruby-forum.com/t/simple-question-about-proxy-cache/227488 "2013-03-17T22:17:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [March 17, 2013, 10:17pm UTC](https://www.ruby-forum.com/t/simple-question-about-proxy-cache/227488/1 "2013-03-17T22:17:55Z")

</div>

I’ve used nginx as a reverse proxy server for a long while but I’ve not  
tried out the proxy cache until today, and I have to say I’m a little  
bit confused by what I’m seeing in the cache log, and I’m wondering  
whether I’ve set things up correctly. My requirements are actually  
pretty simple. I have a couple of locations which I want to proxy to  
another server and cache the results. Thus:

```
       location /media/house_images/{
         proxy_pass http://backend;
         proxy_cache one;
      }

      location /media/boat_images/{
         proxy_pass http://backend;
         proxy_cache one;
      }

```

Apart from this, I don’t want any cacheing of responses to be done. I am  
assuming that the default is NOT to cache unless a cache zone is  
specified (at the server or location level, presumably), so either  
omitting a proxy\_cache or specifying ‘proxy\_cache off’ should be  
sufficient to achieve this, should it not?

Two things are puzzling me, though. Firstly, in the cache log, I’m  
seeing the URLs of all kinds of requests which SHOULD NOT be cached, and  
I’m wondering whether all requests are logged whether they’re cached or  
not - I certainly hope this is the case and it’s not actually cacheing  
these responses. I would definitely prefer to only see entries in the  
log for requests matching locations for which a cache has been  
specified. I presume this is possible?

Secondly, the very requests which I would expect to be cached are all  
showing up in the log with the word ‘MISS’ in the $upstream\_cache\_status  
column.

So, I am worried that I’m currently cacheing everything EXCEPT the pages  
I actually want to be cached!

Could someone please clarify whether my assumptions are correct, and  
maybe explain how I should set up cacheing to do just what I want, in  
the simplest way? Thanks.

John

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [March 18, 2013, 12:08am UTC](https://www.ruby-forum.com/t/simple-question-about-proxy-cache/227488/2 "2013-03-18T00:08:55Z")

</div>

Hello!

On Sun, Mar 17, 2013 at 08:08:39PM +0000, John M. wrote:

> ```
> }
> 
> ```
> 
> omitting a proxy\_cache or specifying ‘proxy\_cache off’ should be  
> sufficient to achieve this, should it not?

Yes, without proxy\_cache (or with “proxy\_cache off”) configured in  
a location cache won’t be used.

> Two things are puzzling me, though. Firstly, in the cache log, I’m  
> seeing the URLs of all kinds of requests which SHOULD NOT be cached, and  
> I’m wondering whether all requests are logged whether they’re cached or  
> not - I certainly hope this is the case and it’s not actually cacheing  
> these responses. I would definitely prefer to only see entries in the  
> log for requests matching locations for which a cache has been  
> specified. I presume this is possible?

You can configure logs for a specific location, see  
[Module ngx\_http\_log\_module](http://nginx.org/r/access_log).

> Secondly, the very requests which I would expect to be cached are all  
> showing up in the log with the word ‘MISS’ in the $upstream\_cache\_status  
> column.

This usually happens if your backend doesn’t specify allowed cache  
time (in this case, proxy\_cache\_valid should be used to set one,  
see [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_cache_valid)) or if backend responses  
doesn’t allow cache to be used (either directly with  
Cache-Control/Expires headers, or indirectly with Set-Cookie  
header, see [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_ignore_headers)).

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
