# Re: Simple question about proxy cache

**URL:** <https://www.ruby-forum.com/t/re-simple-question-about-proxy-cache/227650>\
**Category:** NGINX\
**Created:** [March 22, 2013, 12:18pm UTC](https://www.ruby-forum.com/t/re-simple-question-about-proxy-cache/227650 "2013-03-22T12:18:53Z")\
**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 22, 2013, 12:18pm UTC](https://www.ruby-forum.com/t/re-simple-question-about-proxy-cache/227650/1 "2013-03-22T12:18:53Z")

</div>

On 18/03/13 11:21, John M. wrote:

> > > another server and cache the results. Thus:
> > > 
> > > seeing the URLs of all kinds of requests which SHOULD NOT be cached, and  
> > > column.

Actually, there is one final tweak I’d like. There are a number of  
different locations which I’d like to use the proxy cache for. I cannot  
repeat for each location the block where the cache log is defined (it  
rightly complains about duplication). So I have to define it at a server  
level instead. If I do this, though, then EVERY request for that server  
ends up being logged, even if there is no cache in force for the request  
location (i.e., the location has either ‘proxy\_cache off’ or no  
proxy\_cache definition. Is there a way I can configure things so that  
the only requests which are logged are ones from locations where a proxy  
cache is in force?

---

<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 22, 2013, 12:44pm UTC](https://www.ruby-forum.com/t/re-simple-question-about-proxy-cache/227650/2 "2013-03-22T12:44:00Z")

</div>

Hello!

On Fri, Mar 22, 2013 at 11:18:50AM +0000, John M. wrote:

[…]

> Actually, there is one final tweak I’d like. There are a number of  
> different locations which I’d like to use the proxy cache for. I cannot  
> repeat for each location the block where the cache log is defined (it  
> rightly complains about duplication). So I have to define it at a server  
> level instead. If I do this, though, then EVERY request for that server  
> ends up being logged, even if there is no cache in force for the request  
> location (i.e., the location has either ‘proxy\_cache off’ or no  
> proxy\_cache definition. Is there a way I can configure things so that  
> the only requests which are logged are ones from locations where a proxy  
> cache is in force?

You _can_ repeat acces\_log in every location. If nginx complains -  
you did something wrong (tried to repeat log\_format?).

Something like this will do logging into normal.log for all  
requests, and additionally to cache.log in a locations where it’s  
needed:

```
log_format cache "...";

access_log /path/to/normal.log combined;

server {
    ...

    location / {
        proxy_pass http://uncached;
    }

    location /foo {
        proxy_pass http://foo;
        proxy_cache one;
        access_log /path/to/normal.log combined;
        access_log /path/to/cache.log cache;
    }

    location /bar {
        proxy_pass http://bar;
        proxy_cache one;
        access_log /path/to/normal.log combined;
        access_log /path/to/cache.log cache;
    }
}

```

–  
Maxim D.

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