0

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
3

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/

0

Your problem is here:

Cache-Control: no-store, no-cache ...

Basically:

  • next lookup fails (Varnish will not store the response in cache)
  • browsers will not cache the response so any F5 will request the resource again from your server.

Use the below in your VCL

sub vcl_fetch {  

remove beresp.http.Cache-Control;

  set beresp.http.Cache-Control = "public";

}
  • I added this code to my config , but my website performance did not changed and webpagetest.org still showing the level F of caching – Chris Sep 25 '14 at 10:32
  • The response that your application is returning specifies that it should not be cached. Make sure that you return the public cache headers. – Andy Sep 25 '14 at 10:45
  • yes,i see publish cache in my headers after applying your code :) , but my performance did not changed yet – Chris Sep 25 '14 at 10:47
  • i think i need to adding another configuration , but i don't know what should i do – Chris Sep 25 '14 at 11:00
  • You need to discard backend set-cookie as well. Check varnish-cache.org/docs/3.0/tutorial/cookies.html – Andy Sep 25 '14 at 11:33
0

I had this problem on ubuntu server with PHP-FPM:

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

Problem was session.cache_limiter in /etc/php/7.1/fpm/php.ini (PHP-FPM)

sed -i "s/session.cache_limiter = nocache/session.cache_limiter = ''/" /etc/php/7.1/fpm/php.ini

Other problem to resolve was "SetCookie" for testing use this:

vcl 4.0;

backend default {
    .host = "127.0.0.1";
    .port = "8181";
}

sub vcl_recv {
    unset req.http.cookie;
    return(hash);
}

sub vcl_backend_response {
    unset beresp.http.set-cookie;
    set beresp.ttl = 30m;
}

sub vcl_deliver {
}

One more thing that I was missing was "a2enmod proxy_http" for ProxyPass in Apache2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.