Welcome! Log In Create A New Profile

Advanced

Re: Help: cache or not by cookie

June 20, 2009 09:24AM
On Sat, Jun 20, 2009 at 06:54:57AM -0400, tonyy wrote:

> The requirement is:
>
> When a cookie exist, not return cached file and not cache the response, if the cookie not exist, return cached file and . cache the response.
>
> In the past, we use a standalone cacheserver, the configuration looks like below:
>
> location / {
> if ($http_cookie ~* xxx ) {
> set $cache 0;
> }
>
> if ($cache = 1) {
> proxy_pass http://cacheserver;
> break;
> }
> }
>
> location ~* \.php {
> fastcgi_pass 127.0.0.1:8080;
> }
>
> So, cookie-non-exist visit will be directed to cacheserver, and cookie-exist visit will be directed to fastcgi_pass.
>
> So if we want to remove the cacheserver, and use nginx's cache feature, we need to configure like this:
>
> location ~* \.php {
> fastcgi_pass 127.0.0.1:8080;
> fastcgi_cache php;
> fastcgi_cache_key $request_uri;
> }
>
> Then how can we set cookie-non-exist visits to use cache and cookie-exist visit not to use cache?

No, currently the single way is:

1) add the cookie in proxy_cache_key
proxy_cache_key "http://cacheserver$request_uri $cookie_name";

2) add "X-Accel-Expires: 0" in response with the cookie.

Then requests with the cookie will be sent to a backend since they will
never be cached, and requests without the cookie will be cached.


--
Igor Sysoev
http://sysoev.ru/en/
Subject Author Posted

Help: cache or not by cookie

tonyy June 20, 2009 06:54AM

Re: Help: cache or not by cookie

Igor Sysoev June 20, 2009 09:24AM

Re: Help: cache or not by cookie

Igor Sysoev June 22, 2009 07:32AM

Re: Help: cache or not by cookie

tonyy June 20, 2009 10:04AM

Re: Help: cache or not by cookie

tonyy June 22, 2009 09:53AM

Re: Help: cache or not by cookie

nfn July 08, 2009 06:40PM

Re: Help: cache or not by cookie

Igor Sysoev July 09, 2009 03:05AM

Re: Help: cache or not by cookie

nfn July 09, 2009 06:05AM

Re: Help: cache or not by cookie

Igor Sysoev July 09, 2009 10:26AM

Re: Help: cache or not by cookie

ned0r September 03, 2009 06:53PM

Re: Help: cache or not by cookie

Igor Sysoev September 04, 2009 06:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 140
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready