I am new to Varnish Cache and am wondering. I hope I can help.
I have a very simple and basic setup, but it does not work, as I understand it, it should for some reason.
This is because Varnish does not cache PHP pages that use cookies.
Here is my setup:
1) For my default.vcl, I have a simple backend
backend default { .host = "127.0.0.1"; .port = "80"; }
2) I have a simple PHP file that has only two lines:
session_start(); echo time();
3) When I call this page, it doesnβt cache correctly since I did not add vcl to the required rules
4)
So, according to my understanding of the documentation, I add in these two rules
sub vcl_recv { unset req.http.Cookie; return (lookup); } sub vcl_fetch { unset beresp.http.Set-Cookie; return(deliver); }
5) The PHP page will still not cache. I see that the Set-Cookie header has been removed since I am using FireBug in FireFox.
It is only if I add this to sub vcl_fetch that PHP will cache:
set beresp.ttl = 24h;
My question is, is this correct?
I did not think that I would need to change the ttl of the backend response. I thought that just disable cookies in and supersede PHP w / session for caching.
My full default vcl:
backend default { .host = "127.0.0.1"; .port = "80"; } sub vcl_recv { unset req.http.Cookie; return (lookup); } sub vcl_fetch { unset beresp.http.Set-Cookie; set beresp.ttl = 24h; return(deliver); }
My launch command:
varnishd -f /etc/varnish/default.vcl -s malloc,128M -T 127.0.0.1:2000 -a 0.0.0.0:8080
URL I call:
http:
My index.php file has only:
<?php session_start(); echo time();
I would like to ask the community if this looks right or if I am wrong. In fact, I'm just not sure why to add beresp.ttl = 24h to finally have the page cache in varnish.
I thought that I would not need it.
Any advice is greatly appreciated.
Thanks!
Sincerely.