Proxying and caching a fragile server to ensure availability

cachito nginx-forum at nginx.us
Thu Aug 22 02:35:55 UTC 2013


B.R. Wrote:
-------------------------------------------------------
> Hello,
> 
> On Wed, Aug 21, 2013 at 9:42 PM, cachito <nginx-forum at nginx.us> wrote:
> 
> >   if ($http_cookie ~*
> >
> "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in")
> {
> >     set $no_cache 1;
> >   }
> >
> 
> ​​If the user sends requests using cookies from Wordpress, the cache
> won't
> be used...
> Thus, you seem not to cache requests from Wordpress at all. That CMS
> need
> resources such as power and generates huge traffic (that needs to be
> processed aswell).
> Are you sure not all the Wordpress requests contain cookie(s)?
>
I'm manually deleting cookies to force caching and it isn't happening. Even
if I set $no_cache to 0 in this particular section (or at the end of the if
list) nothing happens.

> 
> 
> > #The different cache zones reside in different filesystems. the
> "pages"
> > zone
> > is saved in RAM for fast delivery.
> >   location / {
> >     proxy_pass http://upstream;
> >     proxy_cache pages;
> >     proxy_cache_key $cache_key;
> >     proxy_cache_valid 60m; # I was hoping to have the proxy query
> the
> > upstream once every hour for updated content.
> >
> 
> ​​Read the correct syntax and use of proxy_cache_valid.
> If no HTTP code is specified as optional parameter, it says 'then only
> 200,
> 301 and 302 responses are cached'.

This is the intended behavior. If the upstream responds something useful,
cache it and serve it. Errors shouldn't be cached, and the stale cache
should be served for that URL.

>> 
> 
> >     # 2 rules to dedicate the no caching rule for logged in users.
> >     proxy_cache_bypass $no_cache; # Do not cache the response.
> >     proxy_no_cache $no_cache; # Do not serve response from cache.
> >
> 
> ​​Actually, those 2 comments are inverted: proxy_no_cache controls
> whether
> or not items should be written in cache and proxy_cache_bypass
> controls
> whether or not content should be read from it.

Comments aside, when $no_cache is set to 0 it mandates that the upstream
response should be cached and the client should be served content from
cache, right?


Thanks B. R.
>> 
> 
> >     add_header X-Cache $upstream_cache_status;
> >     expires 60m;
> >   }
> >
> ---
> *B. R.*
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,242106,242110#msg-242110



More information about the nginx mailing list