【问题标题】:Drupal 7 & Varnish 4 - I always get X-Drupal-Cache: MISS but X-Cache: HITDrupal 7 & Varnish 4 - 我总是得到 X-Drupal-Cache: MISS 但 X-Cache: HIT
【发布时间】:2016-11-11 09:34:51
【问题描述】:

我遇到了和这个人一样的问题:X-Drupal-Cache for Drupal 7 website always hits 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 组织线程中建议的“Varnish Indicator Chrome 扩展”告诉我 Varnish 错过了,但无论我是否登录,都会在我网站的每个页面上。

如果我在 admin/config/development/performance 关闭 为匿名用户关闭 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是直接从this github master with minimum changes抓取的

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

【问题讨论】:

    标签: caching drupal-7 varnish varnish-4 pressflow


    【解决方案1】:

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

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

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

    【讨论】:

    • 这正是问题所在。
    • @CharlieBrown 很高兴我能提供帮助。 :) 接受我的回答plx。
    • 我一看到它就做了,但我没有足够高的声誉来展示它
    猜你喜欢
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-10
    相关资源
    最近更新 更多