0

I have this VCL here https://pastebin.com/RPJvAqZ1 but the varnish Hits are not showing for the JS/CSS

see the headers in the drobpox folder at the bottom (*)

it is a classic/woocomerce/WordPress vcl

I just added:

if (req.http.cookie ~ "learn_press_user_guest_id") {
    return(hash);
  }

and to the has section I added

sub vcl_hash {

hash_data(req.url);

if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}


if (req.http.Cookie) {
hash_data(req.http.Cookie);
}



}

The learnpress cookie is a cookie set for the guest users, so that I had to make that hash, am I right here?

do I have to make one for PHPSESSID?

this is my stats in the dropbox folder (*)

(*) dropbox folder https://www.dropbox.com/sh/lmjkzy0n40vkotq/AAB7p_PK-jaeUsf3cbdasi-Wa?dl=0

please help me.

ahmad
  • 3
  • 3
  • The VCL you have applied is by no means classic and shouldn't be used without at least trying to understand what it does. Based on your screenshot the request for CSS did not even go through Varnish (lacks ```X-Cache``` header that the VCL should apply). So it is not clear what you want to see there. Do not cache on cookies. I'd say your first goal is building up proper VCL for whitelisting Wordpress cookies instead and caching requests that don't have them. – Danila Vershinin May 17 '17 at 23:00
  • thanks for the reply, However, the plugin I use is setting cookies even for guest users, so I must hash it right? – ahmad May 17 '17 at 23:05
  • And I wrote this VCL from various sources online, it basically excludes some pages altogether, and strip some un-necessary cookies, and hash some important cookies. – ahmad May 17 '17 at 23:07
  • I solved the JS/CSS, it was a Nginx mis-config, can u please confirm Im doing it right for the Hashing of the learn-press-cookies? – ahmad May 17 '17 at 23:21
  • I think you just loved to hash things :) But why? Exclude pages from cache where non-essential cookies are present, allow cache when essential cookies are present. Simple. You don't really need to adjust ```vcl_hash``` in most cases with Wordpress. Anyway, the way you're doing it is wrong. Something [like this will work](https://www.varnish-cache.org/lists/pipermail/varnish-misc/2012-November/022623.html). – Danila Vershinin May 17 '17 at 23:38
  • thanks a lot for ur effort, I'm just trying to cach a different version of cache to each visitor instead of not caching at all, as to my knowledge varnish will not cach if there is a cookie and it was reported by some that : non AJAX cart problem, shows empty cart unless we hash it for woocomerce cart cookie – ahmad May 18 '17 at 01:24
  • I removed the hash rules in vcl_recive and inserted this code into vcl_hash [link] (https://pastebin.com/3Y8YS4Vi) but Im getting sytax error on line – ahmad May 18 '17 at 01:30
  • $: Expected an action, 'if', '{' or '}' $: ('/etc/varnish/default.vcl' Line 512 Pos 5) $: remove req.http.X-TMP;} – ahmad May 18 '17 at 01:34
  • That post's VCL is from older version of Varnish. replace ```remove``` with ```unset```. – Danila Vershinin May 18 '17 at 01:51
  • thanks a lot, I also had to remove the last line, `return (hash);` is it fine? – ahmad May 18 '17 at 14:58
  • thanks a lot for bearing with me into this, now Pingdom is showing HIT 1 for the "courses" page where the learn_press_guest_id cookie is set, and when I refresh Pingdom it show HIT 0, this is my latest VCL https://pastebin.com/VPYpMqRp – ahmad May 18 '17 at 17:04
  • If you don't include ```return (hash);``` then it will proceed to ```vcl_hash``` of ```builtin.vcl``` which already includes some of your logic. So either keep ```return (hash);``` or remove hashing on URL, host, IP (which is what ```builtin.vcl``` has). If the cookie is being set while accessing "courses" (i.e. ```Set-Cookie```) you never should cache the page. If it's being set elsewhere (i.e. login-like) page and you hash on that, Pingdom will always display HIT 0, since the cache is specific to browser session.. It's just not clear when this particular cookie is set. – Danila Vershinin May 18 '17 at 17:55
  • I replaced `return (hash);` with `return (lookup);` as the compiler said so "Legal returns are: "fail" "lookup" I'm on varnish 5, I need to see a good thing about that plugin who sets that cookie everywhere, or else Im not getting a benfeit from varnish, will test the new "lookup" and see – ahmad May 18 '17 at 18:21
  • the cookie learn_press_guest is set on courses pages (not on login like its everywhere in courses) and that is the main website contents : courses:, I included it on the sub_vcl_hash ` if (req.http.cookie ~ "learn_press_user_guest_id=") { set req.http.X-TMP = regsub(req.http.cookie, ".*learn_press_user_guest_id=([^;]+);.*", "\1"); hash_data(req.http.X-TMP); unset req.http.X-TMP;} ` – ahmad May 18 '17 at 18:39
  • also I removed this from sub_vcl_recive `if (req.http.cookie ~ "learn_press_user_guest_id") { return(hash); }` and only left the code of the sub_vcl_hash – ahmad May 18 '17 at 19:01
  • Am I on the right track? – ahmad May 20 '17 at 09:00

0 Answers0