Cache always shows expired status for anonymous users

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cache always shows expired status for anonymous users

Quintin Par

I have my homepage cached as shown

location = / {

  if (-f /var/www/statichtmls/during_build.html) {

  return 503;

  }

  set $country_code $http_x_country_code;

  set_if_empty $country_code $geoip_country_code;

 

  limit_req zone=pw burst=5 nodelay;

  proxy_pass  http://localhost:82;

  proxy_set_header   Host             $host;

  proxy_set_header   X-Real-IP        $remote_addr;

  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

  proxy_set_header   X-Country-Code   $country_code;

  proxy_set_header Accept-Encoding "";

  proxy_ignore_headers Cache-Control;

  proxy_ignore_headers Expires;

  proxy_ignore_headers X-Accel-Expires;

  add_header X-Cache-Status $upstream_cache_status;

  proxy_cache             cache;

  proxy_cache_key         $scheme$host$request_uri$cookie_sessionid$country_code;

  proxy_cache_valid       200 302 2m;

  proxy_cache_use_stale   updating;

}

But every time I hit the page as an anonymous user it shows

X-Cache-Status: EXPIRED   


user$ curl -I site.com

HTTP/1.1 200 OK

Server: ngx_openresty

Date: Fri, 19 Oct 2012 02:15:32 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

Keep-Alive: timeout=60

Vary: Accept-Encoding

Vary: Cookie

Set-Cookie: csrftoken=Dl4mvy4Rky7sfZwqek27hFrCXzWCi9As; expires=Fri, 18-Oct-2013 02:15:32

 GMT; Max-Age=31449600; Path=/

X-Cache-Status: EXPIRED

I want to cache it both for logged in and anonymous and it looks like the absence of session cookie is creating issues.

How do I cache the homepage correctly?


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Cache always shows expired status for anonymous users

Quintin Par
I realized my folly. Set-Cookie for csrf token is invalidating the cache!

- Quintin

On Fri, Oct 19, 2012 at 7:50 AM, Quintin Par <[hidden email]> wrote:

I have my homepage cached as shown

location = / {

  if (-f /var/www/statichtmls/during_build.html) {

  return 503;

  }

  set $country_code $http_x_country_code;

  set_if_empty $country_code $geoip_country_code;

 

  limit_req zone=pw burst=5 nodelay;

  proxy_pass  http://localhost:82;

  proxy_set_header   Host             $host;

  proxy_set_header   X-Real-IP        $remote_addr;

  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

  proxy_set_header   X-Country-Code   $country_code;

  proxy_set_header Accept-Encoding "";

  proxy_ignore_headers Cache-Control;

  proxy_ignore_headers Expires;

  proxy_ignore_headers X-Accel-Expires;

  add_header X-Cache-Status $upstream_cache_status;

  proxy_cache             cache;

  proxy_cache_key         $scheme$host$request_uri$cookie_sessionid$country_code;

  proxy_cache_valid       200 302 2m;

  proxy_cache_use_stale   updating;

}

But every time I hit the page as an anonymous user it shows

X-Cache-Status: EXPIRED   


user$ curl -I site.com

HTTP/1.1 200 OK

Server: ngx_openresty

Date: Fri, 19 Oct 2012 02:15:32 GMT

Content-Type: text/html; charset=utf-8

Connection: keep-alive

Keep-Alive: timeout=60

Vary: Accept-Encoding

Vary: Cookie

Set-Cookie: csrftoken=Dl4mvy4Rky7sfZwqek27hFrCXzWCi9As; expires=Fri, 18-Oct-2013 02:15:32

 GMT; Max-Age=31449600; Path=/

X-Cache-Status: EXPIRED

I want to cache it both for logged in and anonymous and it looks like the absence of session cookie is creating issues.

How do I cache the homepage correctly?



_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx