Forum: NGINX fastcgi_cache

2974d09ac2541e892966b762aad84943?d=identicon&s=25 ariel_esp (Guest)
on 2014-06-23 16:56
(Received via mailing list)
Hi,
I am trying setup fastcgi_cache.
Working fine.... BUT I need bypass some pages... when theses pages have
header "no-cache".... but I dont know how to do this...
The rules for bypass using urls, work fine.. like this:

[code]
if ($request_uri ~*
"(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)")
{
        set $cache_uri 'null cache';
    }
[/code]

How can I bypass cache setting header page "no-cache" ?
Example, in varnish work fine:
 if (req.http.Cache-Control ~ "no-cache")
{
    return (pipe);
}

thanks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,251112,251112#msg-251112
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-06-23 18:45
(Received via mailing list)
Hello!

On Mon, Jun 23, 2014 at 10:56:17AM -0400, ariel_esp wrote:

>         set $cache_uri 'null cache';
>     }
> [/code]
>
> How can I bypass cache setting header page "no-cache" ?
> Example, in varnish work fine:
>  if (req.http.Cache-Control ~ "no-cache")
> {
>     return (pipe);
> }

http://nginx.org/r/fastcgi_cache_bypass

--
Maxim Dounin
http://nginx.org/
2974d09ac2541e892966b762aad84943?d=identicon&s=25 ariel_esp (Guest)
on 2014-06-23 19:09
(Received via mailing list)
Hi, I already try this... but... not work =/
when in the page, I do "shift+f5", page is re-read "EXPIRED"... OK
but, this entering in the page, or do F5 ... page = HIT cache...
In this specifics pages, I always put php header "cache-control, pragma,
etc" as "no-cache", so, I want always get a new page from backend...
understand?


fastcgi_cache           microcache;
fastcgi_cache_key
$scheme$request_method$host$request_uri$http_x_custom_header;
fastcgi_cache_valid     any 1m;
proxy_cache_use_stale   error timeout invalid_header updating http_500
http_502 http_503 http_504;
fastcgi_cache_lock      on;
add_header              Fastcgi-Cache $upstream_cache_status;

if ($cache_uri != "null cache")
{
add_header              Fastcgi-Cache $upstream_cache_status;
add_header              X-Cache-Debug "$cache_uri $cookie_nocache
$arg_nocache$arg_comment $http_pragma $http_authorization";
set $skip_cache         0;
}

fastcgi_cache_bypass    $skip_cache;
fastcgi_no_cache        $skip_cache;

fastcgi_cache_bypass    $cookie_nocache $arg_nocache$arg_comment ;
fastcgi_no_cache        $cookie_nocache $arg_nocache$arg_comment;

fastcgi_cache_bypass    $http_pragma $http_authorization ;
fastcgi_no_cache        $http_pragma    $http_authorization;

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,251112,251115#msg-251115
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-06-24 04:28
(Received via mailing list)
Hello!

On Mon, Jun 23, 2014 at 01:08:33PM -0400, ariel_esp wrote:

> Hi, I already try this... but... not work =/
> when in the page, I do "shift+f5", page is re-read "EXPIRED"... OK
> but, this entering in the page, or do F5 ... page = HIT cache...
> In this specifics pages, I always put php header "cache-control, pragma,
> etc" as "no-cache", so, I want always get a new page from backend...
> understand?

As long as _response_ headers contain "Cache-Control: no-cache",
nginx will not cache a response, unless explicitly asked to ignore
the Cache-Control header (using the fastcgi_ignore_headers
directive).  No special handling is needed, it will just work.

If it doesn't work for you, this likely means that:

- either you did something wrong in your nginx config (i.e., used
  fastcgi_ignore_headers to disable Cache-Control handling);

- or you wrote the "Cache-Control: no-cache" incorrectly.

--
Maxim Dounin
http://nginx.org/
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.