Varnish 不缓存任何东西:varnishstat 的比例总是 0

Varnish 不缓存任何东西:varnishstat 的比例总是 0

我已经设置了 apache 和 Varnish,无需特别配置(apache 在 8080 上,varnish 在端口 80 上提供页面)。我还在 Varnish 中放置了 cookie,以确保最大程度地缓存 Wordpress 网站。

网站可以正常运行,可以加载等等;但 Varnish 似乎不缓存任何东西。当我打开 Varnishstat 时,我总是看到 Hitrate ratio: 0;以及大量“inf backend_busy”、“inf backend_reuse”等等;并且没有 accepted_connections。以下是示例:

0+00:00:00
Hitrate ratio:        0        0        0
Hitrate avg:     0.0000   0.0000   0.0000

         146         0.00          inf backend_busy - Backend conn. too many
         164         0.00          inf backend_reuse - Backend conn. reuses
          16         0.00          inf backend_toolate - Backend conn. was closed
         101         0.00          inf backend_recycle - Backend conn. recycles
          47         0.00          inf backend_retry - Backend conn. retry
         111         0.00          inf fetch_head - Fetch head

怎么会?

更新:Varnishlog:

        0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712509 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712512 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712515 1.0
   13 BackendClose - default
   13 BackendOpen  b default 127.0.0.1 38776 127.0.0.1 8080
   13 BackendXID   b 1420058564
   13 TxRequest    b GET
   13 TxURL        b /
   13 TxProtocol   b HTTP/1.1
   13 TxHeader     b Host: www.test-mystreaming.it
   13 TxHeader     b Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
   13 TxHeader     b User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
   13 TxHeader     b Accept-Language: en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4
   13 TxHeader     b X-Forwarded-For: 2.229.61.20
   13 TxHeader     b X-Varnish: 1420058564
   13 TxHeader     b Accept-Encoding: gzip
   13 RxProtocol   b HTTP/1.1
   13 RxStatus     b 200
   13 RxResponse   b OK
   13 RxHeader     b Date: Thu, 13 Mar 2014 12:08:37 GMT
   13 RxHeader     b Server: Apache/2.2.22 (Ubuntu)
   13 RxHeader     b X-Powered-By: PHP/5.3.10-1ubuntu3.10
   13 RxHeader     b X-Pingback: http://www.test-mystreaming.it/xmlrpc.php
   13 RxHeader     b Vary: Accept-Encoding
   13 RxHeader     b Content-Encoding: gzip
   13 RxHeader     b Content-Length: 7682
   13 RxHeader     b Content-Type: text/html; charset=UTF-8
   13 Fetch_Body   b 4(length) cls 0 mklen 1
   13 Length       b 7682
   13 BackendReuse b default
   11 SessionOpen  c 2.229.61.20 56012 :80
   11 ReqStart     c 2.229.61.20 56012 1420058564
   11 RxRequest    c GET
   11 RxURL        c /
   11 RxProtocol   c HTTP/1.1
   11 RxHeader     c Host: www.test-mystreaming.it
   11 RxHeader     c Connection: keep-alive
   11 RxHeader     c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
   11 RxHeader     c User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
   11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
   11 RxHeader     c Accept-Language: en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4
   11 RxHeader     c Cookie: wp-settings-1=m5%3Do%26m4%3Do%26hidetb%3D1%26m9%3Do%26m1%3Do%26imgsize%3Dfull%26editor%3Dhtml%26libraryContent%3Dbrowse; wp-settings-time-1=1394014590; _xyz_lbx_until=1; _xyz_lbx_pc=1; __utma=257699214.1231191244.1394014450.1394039099.1394709725.5
   11 VCL_call     c recv lookup
   11 VCL_call     c hash
   11 Hash         c /
   11 Hash         c www.test-mystreaming.it
   11 VCL_return   c hash
   11 VCL_call     c miss fetch
   11 Backend      c 13 default default
   11 TTL          c 1420058564 RFC 120 -1 -1 1394712518 0 1394712517 0 0
   11 VCL_call     c fetch deliver
   11 ObjProtocol  c HTTP/1.1
   11 ObjResponse  c OK
   11 ObjHeader    c Date: Thu, 13 Mar 2014 12:08:37 GMT
   11 ObjHeader    c Server: Apache/2.2.22 (Ubuntu)
   11 ObjHeader    c X-Powered-By: PHP/5.3.10-1ubuntu3.10
   11 ObjHeader    c X-Pingback: http://www.test-mystreaming.it/xmlrpc.php
   11 ObjHeader    c Vary: Accept-Encoding
   11 ObjHeader    c Content-Encoding: gzip
   11 ObjHeader    c Content-Type: text/html; charset=UTF-8
   11 Gzip         c u F - 7682 33861 80 80 61389
   11 VCL_call     c deliver deliver
   11 TxProtocol   c HTTP/1.1
   11 TxStatus     c 200
   11 TxResponse   c OK
   11 TxHeader     c Server: Apache/2.2.22 (Ubuntu)
   11 TxHeader     c X-Powered-By: PHP/5.3.10-1ubuntu3.10
   11 TxHeader     c X-Pingback: http://www.test-mystreaming.it/xmlrpc.php
   11 TxHeader     c Vary: Accept-Encoding
   11 TxHeader     c Content-Encoding: gzip
   11 TxHeader     c Content-Type: text/html; charset=UTF-8
   11 TxHeader     c Content-Length: 7682
   11 TxHeader     c Accept-Ranges: bytes
   11 TxHeader     c Date: Thu, 13 Mar 2014 12:08:38 GMT
   11 TxHeader     c X-Varnish: 1420058564
   11 TxHeader     c Age: 0
   11 TxHeader     c Via: 1.1 varnish
   11 TxHeader     c Connection: keep-alive
   11 Length       c 7682
   11 ReqEnd       c 1420058564 1394712517.488089323 1394712518.017520905 0.000098944 0.529357433 0.000074148
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712518 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712521 1.0

答案1

要确定响应是否可缓存,请将以下内容添加到您的 VCL,并varnishlog在更改后使用输出更新您的问题。另外,请发布您的 varnish 命令行,尤其是默认 TTL(-t参数)。由于您的后端服务器未发送Cache-Control标头,并且您未beresp.ttl在 中定义vcl_fetch,因此 Varnish 使用通过-t开关定义的 TTL 默认值。

以下 VCL 将向每个请求添加X-Cacheable和标头。X-ttl

sub vcl_fetch {

  # Varnish determined the object was not cacheable
  if (!(beresp.ttl > 0s)) {
    set beresp.http.X-Cacheable = "NO:Not Cacheable, ttl <0s";
    set beresp.http.X-ttl = beresp.ttl;
    return(hit_for_pass);
  }
  elseif (req.http.Cookie) {
    set beresp.http.X-Cacheable = "NO:Got cookie";
    set beresp.http.X-Cookie = req.http.Cookie;
    return(hit_for_pass);
  }
  elseif (beresp.http.Cache-Control ~ "private") {
    set beresp.http.X-Cacheable = "NO:Cache-Control=private";
    return(hit_for_pass);
  }
  elseif (beresp.http.Cache-Control ~ "no-cache" || beresp.http.Pragma ~ "no-cache") {
    set beresp.http.X-Cacheable = "Refetch forced by user";
    return(hit_for_pass);
  # You are extending the lifetime of the object artificially
  }
  elseif (beresp.ttl < 1s) {
    set beresp.ttl   = 5s;
    set beresp.grace = 5s;
    set beresp.http.X-Cacheable = "YES:FORCED";
  # Varnish determined the object was cacheable
  } else {
    set beresp.http.X-Cacheable = "YES";
    set beresp.http.X-ttl = beresp.ttl;
  }
}

相关内容