Homepage cache and cookies

B.R. reallfqq-nginx at yahoo.fr
Thu Mar 24 17:04:14 UTC 2016


The proxy_cache_key defines which key differentiate any cache object. By
using $cookie_name in the string, the *value* of the cookie 'name' will be
taken as part of the key.
If multiple clients have the same combination of variables value
(specifically, for cookie, presence, no presence or same value-s), they
will grab the same object from the cache. If different content might get
produced/grabbed with the same value in variables, then you have a problem.

As a sidenote, you are using proxy_pass_header Set-Cookie with
proxy_hide_header Set-Cookie, which conflict one with each other. Remove
them altogether.
---
*B. R.*

On Thu, Mar 24, 2016 at 2:14 PM, john_smith77 <nginx-forum at forum.nginx.org>
wrote:

> I am trying to cache the home page to a site. I am only caching the home
> page. If I put in a condition to check for cookies existing before caching,
> everything works as expected, but there is a high BYPASS rate due to the
> client not having the cookies the first time they visit the site. Once I
> took out the check for cookies, clients started getting cached cookies from
> other users. Is there a way to still have the cookies set from the origin
> server, and have a cache hit?
>
> server {
>     listen       80;
>
>     if ($request_uri !~* "home.html") {
>                 set $skip_cache 1; }
>
>     location / {
>         proxy_pass http://backend;
>         proxy_set_header Host      $host;
>         proxy_cache_bypass $skip_cache;
>         proxy_no_cache $skip_cache;
>         proxy_pass_header Set-Cookie;
>         proxy_cache one;
>         proxy_cache_key
> $scheme$proxy_host$uri$is_args$args$cookie_myCookie$cookie_myOtherCookie;
>         proxy_cache_valid  200 302  10m;
>         proxy_cache_valid  404      1m;
>         proxy_ignore_headers "Set-Cookie" "Cache-Control" "Expires";
>         proxy_hide_header "Set-Cookie";
>         proxy_cache_lock on;
>         if ($http_user_agent ~*
>
> '(iPhone|Android|Phone|PalmSource|BOLT|Symbian|Fennec|GoBrowser|Maemo|MIB|Minimo|NetFront|Presto|SEMC|Skyfire|TeaShark|Teleca|uZard|palm|psp|openweb|mmp|novarra|nintendo
> ds|hiptop|ipod|blackberry|up.browser|up.link|wap|windows
> ce|blackberry|iemobile|bb10)' ) {
>                 proxy_pass http://backend_mobile; }
>         if ($http_user_agent ~* '(iPad|playbook|hp-tablet|kindle|Silk)' ) {
>                 proxy_pass http://backend_tablet; }
>
>         root   /opt/rh/rh-nginx18/root/usr/share/nginx/html;
>         index  index.html index.htm;
>     }
>
> Posted at Nginx Forum:
> https://forum.nginx.org/read.php?2,265629,265629#msg-265629
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160324/7481fe86/attachment.html>


More information about the nginx mailing list