简体   繁体   中英

Drupal 7 & Varnish 4 - I always get X-Drupal-Cache: MISS but X-Cache: HIT

I have run into the same issue as this person: X-Drupal-Cache for Drupal 7 website always hits MISS , and can not find a way out.

I am running Drupal 7 - Pressflow

and

Varnish 4.0

When I curl I get this result:

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 tells me: "You deserve a gold star, here you go: gold star badge" ....

While the "Varnish Indicator Chrome Extension" suggested in the linked Drupal org thread, tells me Varnish missed, on every single page of my website regardless if I am logged in or not.

If I turn Drupal cache for anonymous users at admin/config/development/performance off , Varnish will not work at all. If I set different minimum cache lifetimes there, it makes no difference.

In my settings.php I have this:

$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;

and this

 $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';

while this has been commented out from the Varnish config in settings.php because if I don't, Varnish fails:

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

I have turned off all modules that could interfere, such as captcha modules, and I will note that the statistics won't count node hits correctly now, so something is being cached...

The VCL I use is grabbed straight from this github master with minimum changes

How can I troubleshoot this X-Drupal-Cache: MISS issue?

Your backend is clearly sending cookies:

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

In default configuration, Varnish will not cache a object coming from the backend with a Set-Cookie header present. Also, if the client sends a Cookie header, Varnish will bypass the cache and go directly to the backend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM