Welcome! Log In Create A New Profile

Advanced

Re: Simple question about proxy cache

J2R
March 22, 2013 07:20AM
On 18/03/13 11:21, John Moore wrote:
> On 17/03/13 23:08, Maxim Dounin wrote:
>> Hello!
>>
>> On Sun, Mar 17, 2013 at 08:08:39PM +0000, John Moore wrote:
>>
>>> 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?
>> 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
>> 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 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 http://nginx.org/r/proxy_ignore_headers).
>>
> Excellent - thanks, Maxim! That's got me sorted now, it all seems to be
> working as planned.
>
>

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?

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Simple question about proxy cache

J2R March 17, 2013 05:18PM

Re: Simple question about proxy cache

Maxim Dounin March 17, 2013 07:10PM

Re: Simple question about proxy cache

J2R March 18, 2013 07:22AM

Re: Simple question about proxy cache

J2R March 22, 2013 07:20AM

Re: Simple question about proxy cache

Maxim Dounin March 22, 2013 07:44AM

Re: Simple question about proxy cache

J2R March 22, 2013 07:40AM

Re: Simple question about proxy cache

J2R March 22, 2013 08:26AM

Re: Simple question about proxy cache

Maxim Dounin March 22, 2013 10:12AM

Re: Simple question about proxy cache

J2R March 22, 2013 11:40AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 92
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready