Welcome! Log In Create A New Profile

Advanced

Re: Homepage cache and cookies

B.R.
March 24, 2016 01:06PM
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@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@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Homepage cache and cookies

john_smith77 March 24, 2016 09:14AM

Re: Homepage cache and cookies

B.R. March 24, 2016 01:06PM

Re: Homepage cache and cookies

john_smith77 March 24, 2016 04:31PM

Re: Homepage cache and cookies

B.R. March 25, 2016 04:40AM

Re: Homepage cache and cookies

john_smith77 March 25, 2016 09:06AM

Re: Homepage cache and cookies

john_smith77 March 25, 2016 05:33PM

Re: Homepage cache and cookies

ph.gras March 25, 2016 06:10PM

Re: Homepage cache and cookies

B.R. March 26, 2016 06:36AM

Re: Homepage cache and cookies

john_smith77 March 28, 2016 09:51AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 289
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready