Varnish Does not work

varnish

I installed varnish as well on my server , but the performance did not change , The http://www.webpagetest.org/ says caching system does not enable on your server , i'm using default configuration of varnish , it's my header :

status: HTTP/1.1 200 OK
Server: Apache  
X-Powered-By:   PHP/5.3.29  
P3P:    CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"  
Expires:    Mon, 1 Jan 2001 00:00:00 GMT    
Cache-Control:  no-store, no-cache, must-revalidate, post-check=0, pre-check=0  
Pragma: no-cache    
Set-Cookie: 73ab794b527721e09d2124da5815cf79=2f8ca1fed15724e75f5bf3824a26a9cd; path=/; HttpOnly 
Last-Modified:  Thu, 25 Sep 2014 08:28:53 GMT   
Content-Type:   text/html; charset=utf-8    
Content-Length: 77965   
Accept-Ranges:  bytes   
Date:   Thu, 25 Sep 2014 08:28:53 GMT   
X-Varnish:  1531877383  
Age:    0   
Via:    1.1 varnish 
Connection: close

Best Answer

I will see if i can help for any future views of this issue, There are a number of things that will cause Varnish not to cache content. You will need to work through all of them and hopefully have a good logging / metrics setup so you can identify which pages / resources are not responding from cache.

Your cache control headers were:

status: HTTP/1.1 200 OK
Server: Apache  
X-Powered-By:   PHP/5.3.29  
P3P:    CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"  
Expires:    Mon, 1 Jan 2001 00:00:00 GMT    
Cache-Control:  no-store, no-cache, must-revalidate, post-check=0, pre-check=0  
Pragma: no-cache    
Set-Cookie: 73ab794b527721e09d2124da5815cf79=2f8ca1fed15724e75f5bf3824a26a9cd; path=/; HttpOnly 
Last-Modified:  Thu, 25 Sep 2014 08:28:53 GMT   
Content-Type:   text/html; charset=utf-8    
Content-Length: 77965   
Accept-Ranges:  bytes   
Date:   Thu, 25 Sep 2014 08:28:53 GMT   
X-Varnish:  1531877383  
Age:    0   
Via:    1.1 varnish 
Connection: close

To have this particular request cachable you need to fix:

  • Expires: Mon, 1 Jan 2001 00:00:00 GMT

    This tells Varnish not to cache

  • Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

    This tells Varnish not to cache (Varnish 4+, Varnish 3 will still cache this)

  • Set-Cookie: 73ab794b527721e09d2124da5815cf79=2f8ca1fed15724e75f5bf3824a26a9cd; path=/; HttpOnly

    Varnish will not cache any response with Set-Cookie

In order to tackle metrics / logging so that you can get visibility of all requests i have written about Varnish setup options: https://www.section.io/varnish-install-quick-and-detailed/

Related Topic