2

我遇到了和这个人一样的问题:Drupal 7 网站的 X-Drupal-Cache 总是点击 MISS,找不到出路。

我正在运行 Drupal 7 - Pressflow

清漆 4.0

当我卷曲时,我得到了这个结果:

TTP/1.1 200 OK
Date: Fri, 08 Jul 2016 17:45:08 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=db5fd757e7485622ac16af86f292603f51467999908; expires=Sat, 08-Jul-17 17:45:08 GMT; path=/; domain=.adland.tv; HttpOnly
X-Content-Type-Options: nosniff
**X-Drupal-Cache: MISS**
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: public, max-age=86400
X-Content-Type-Options: nosniff
Content-Language: en
X-Generator: Drupal 7 (http://drupal.org)
Last-Modified: Fri, 08 Jul 2016 17:41:27 GMT
Vary: Accept-Encoding
X-Varnish: 196743 3
Age: 213
Via: 1.1 varnish-v4
**X-Cache: HIT**
X-Cache-Hits: 22
Server: cloudflare-nginx
CF-RAY: 2bf55922d49b23d8-IAD

isvarnishworking.com告诉我: “你应该得到一颗金星,给你:金星徽章” ......

虽然链接的 Drupal org 线程中建议的“Varnish Indicator Chrome Extension”告诉我 Varnish 错过了,在我网站的每个页面上,无论我是否登录。

如果我在 admin/config/development/performance off为匿名用户关闭 Drupal 缓存,Varnish 将根本无法工作。如果我在那里设置不同的最小缓存寿命,那没有什么区别。

在我的 settings.php 我有这个:

$conf['varnish_version'] = 4;
$conf['reverse_proxy'] = True;
$conf['reverse_proxy_addresses'] = array('127.0.0.1');
$conf['page_cache_invoke_hooks'] = FALSE;
$conf['page_cache_maximum_age'] = 86400;
$conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc';
$conf['cache_class_cache_page'] = 'VarnishCache';
$conf['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR';
$conf['omit_vary_cookie'] = True;
$conf['drupal_http_request_fails'] = FALSE;

和这个

 $conf['cache_backends'][] = 'sites/all/modules/filecache/filecache.inc';
 $conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.cache.inc';
 $conf['cache_backends'][] = 'sites/all/modules/authcache/modules/authcache_builtin/authcache_builtin.cache.inc';
 $conf['cache_class_cache_page'] = 'DrupalFileCache';

虽然这已从 settings.php 中的 Varnish 配置中注释掉,因为如果我不这样做,Varnish 会失败:

//$conf['cache'] = 1;
//$conf['cache_lifetime'] = 01080;

我已经关闭了所有可能干扰的模块,例如验证码模块,并且我会注意到统计信息现在不会正确计算节点命中,所以正在缓存一些东西......

我使用的 VCL 直接从这个 github master 中获取,改动最少

如何解决此X-Drupal-Cache: MISS问题?

4

1 回答 1

0

您的后端显然正在发送 cookie:

Set-Cookie: __cfduid=db5fd757e7485622ac16af86f292603f51467999908; expires=Sat, 08-Jul-17 17:45:08 GMT; path=/; domain=.adland.tv; HttpOnly

在默认配置中,Varnish 不会缓存来自后端的带有 Set-Cookie 标头的对象。另外,如果客户端发送了 Cookie 头,Varnish 会绕过缓存直接进入后端。

于 2017-02-13T17:24:14.340 回答