Hi,
After making my homepage work with autcache + authcache_ajax for anonymous and authenticated users, I followed the instructions to do the same with Varnish + ESI (https://drupal.org/node/2162047).
Unfortunately, I can't even see a HIT on varnish cache for anonymous user with the minimal VCL provided in the instructions, see headers:
Accept-Ranges bytes
Age 0
Cache-Control no-cache, must-revalidate, post-check=0, pre-check=0
Connection keep-alive
Content-Encoding gzip
Content-Language fr
Content-Length 12010
Content-Type text/html; charset=utf-8
Date Tue, 04 Mar 2014 15:42:05 GMT
Etag "1393947725"
Expires Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified Tue, 04 Mar 2014 15:42:05 +0000
Server nginx/1.2.1
Vary X-Authcache-Key
Via 1.1 varnish
X-Generator Drupal 7 (http://drupal.org)
X-Powered-By PHP/5.4.4-14+deb7u7
X-Varnish 795006919
Here is the minimal VCL:
backend default {
.host = "127.0.0.1";
.port = "80";
}
/**
* Remove all cookies from a request unless there is a session open.
*/
sub vcl_recv {
if (req.http.Cookie !~ "SESS") {
unset req.http.Cookie;
}
}
/**
* If no cookies are on the request, add has_js before passing to the backend.
*/
sub vcl_pass {
if (!req.http.Cookie) {
set bereq.http.Cookie = "has_js=1";
}
}
/**
* If no cookies are on the request, add has_js before fetching a fresh copy
* from the backend.
*/
sub vcl_miss {
if (!req.http.Cookie) {
set bereq.http.Cookie = "has_js=1";
}
}
settings.php:
$conf['reverse_proxy'] = TRUE;
$conf['reverse_proxy_addresses'] = array('127.0.0.1');
$conf['cache_backends'][] = 'sites/all/modules/contrib/varnish/varnish.cache.inc';
$conf['cache_class_cache_page'] = 'VarnishCache';
I also tried with the full example VCL (http://paste.debian.net/85255/), and I get MISS for anonymous user. Output of authcache_debug:
Authcache Debug
StatusCache Status: "MISS"
Page Render Time: "854.28 ms"
Page Age: "2 seconds"
SettingsDebug Users: ["membre"]
Cache User: 0
Cache Backends: "authcache_varnish"
Active Backend: "authcache_varnish"
Authcache Key: "http://varnish.dev.wesumone.com:6081"
Cache-Control: "public, max-age=300"
Via reverse proxy: "yes"
HTML/JavaScript time: 135 ms
I also get CANCELED for logged in users:
Authcache Debug
StatusCache Status: "Caching CANCELED"
Message 1: "Canceled: No client for fragment form-token"
Page Render Time: "1326.13 ms"
Page Age: "1 seconds"
SettingsDebug Users: ["membre"]
Cache User: "380"
Cache Backends: "authcache_varnish"
Active Backend: "authcache_varnish"
Authcache Key: "347d0e9"
Key props: {"base_root":"http://varnish.dev.wesumone.com:6081","roles":[2],"esi":false}
Cache-Control: "no-cache, must-revalidate, post-check=0, pre-check=0"
Via reverse proxy: "Oui"
HTML/JavaScript time: 134 ms
Finally I should say that admin/reports/authcache-esi-debug-status always gives me errors and I couldn't find a proper way to fix them:
Request Header HTTP header X-Authcache-Do-ESI is not on primary request.
Please make sure that the reverse proxy software (varnish) is configured according to the requirements of authcache_esi / authcache_varnish.
Erreur
ESI Tag ESI tag not substituted.
Please make sure that the reverse proxy software (varnish) is configured according to the requirements of authcache_esi / authcache_varnish.
The architecture is as follow:
- Remote machine with Varnish on 6081
- Same remote machine with Drupal on 80
- Obviously I browse the site through :6081
Any help appreciated! Kind of stuck here. Thanks.
Comments
Comment #1
znerol CreditAttribution: znerol commentedIn order to make the minimal example work (Level 1 - section from the documentation), ensure the following:
Comment #2
abulte CreditAttribution: abulte commentedHi znerol, thanks for taking some time for me.
I have done all you described (especially private mode window) and I still get MISS
But maybe we need to concentrate not on this minimal vcl / anonymous case but on the full configuration I have already been working on. How can I solve the errors on admin/reports/authcache-esi-debug-status for example? (I get them with the full VCL linked here http://paste.debian.net/85255/)
Comment #3
znerol CreditAttribution: znerol commentedIt is easier to find the culprit when using the minimal VCL. Therefore I recommend to stick with that until you've found the reason why varnish is not reporting cache-hits.
After changing the VCL be sure to:
X-Varnish
reports only one value (cache miss)X-Varnish
reports two values (cache hit)Also disable the browser cache while debugging. In some browsers there is an option in the developer tools to disable the cache as long as the development tools are enabled.
Comment #4
abulte CreditAttribution: abulte commentedLet's go then ;-)
- Changed VCL to minimal http://paste.debian.net/85419/
- Restarted Varnish
- drush cc all
- Close Firefox
- Start Firefox and start new private browser window
- Disabled all cache with web dev toolbar
- Still no luck, always MISS, full request and response headers below
Enabled authcache modules:
Comment #5
znerol CreditAttribution: znerol commentedBingo! Varnish is bypassed for pages requiring HTTP authorization due to the vcl_recv of the
default.vcl
:https://www.varnish-software.com/static/book/VCL_Basics.html#default-vcl...
Comment #6
abulte CreditAttribution: abulte commentedOk that was nasty ;-) Thanks!
Comment #7
abulte CreditAttribution: abulte commentedNow I have two values on X-Varnish but still MISS on X-Drupal-Cache. Is it OK?
Comment #8
znerol CreditAttribution: znerol commentedYes, this is okay. The
X-Drupal-Cache
header is added by the Authcache Builtin Storage Backend. The header was cached along with the rest of the page by Varnish.Comment #9
abulte CreditAttribution: abulte commentedOkay now I'm trying to move on to the real VCL (http://paste.debian.net/85255/) and ESI, still following the migration guide.
For anonymous, no luck (authcache debug says MISSED):
For authenticated user (authcache debug says Canceled: No client for fragment form-token):
ESI debug page says:
Comment #10
znerol CreditAttribution: znerol commentedMaybe the
Host
-header? On the request it is like:However Example 3 in
vcl_recv
is testing for the domain-part only. I guess either you need to include the port or use a pattern matching operator (e.g.req.http.host !~ "varnish\.dev\.wesumone\.com"
) matching for a substring instead of the whole value. For testing purposes I recommend to comment out Example 3 altogether and only introduce it when the rest works.Comment #11
abulte CreditAttribution: abulte commentedAnd once again, you are exactly right! I'm now being reported cache HIT on both anonymous and authenticated users. So far, so good.
Comment #12
abulte CreditAttribution: abulte commentedI know face a strange problem in Firefox. My Varnish cache is filled with authenticated user home page, which is cool. But when I logout, I'm still recognized as an authenticated user and served the authenticated user home page.
This does not happen in Safari: I have cache hit on authenticated user home page but once I visit user/logout I'm recognized as anonymous and get a cache HIT on anonymous user home page.
Reading the commented VCL, I thought I would see requests to /authcache-varnish-get-key in Firebug which would help differentiate roles but I don't see any.
I would like to sort out this role based caching stuff before digging into ESI... Any advice here?
Comment #13
znerol CreditAttribution: znerol commentedI'm just repeating this because it is important: Pay attention to the cookies in your browser. The best way to ensure that no (possibly duplicate) session-cookies are on the request is to start out with a fresh private browser session.
That said, also keep an eye on your browsers cache. Safari has a known bug where stale pages may be served from the browser cache instead of fresh ones, even when the server correctly returns a
Vary: Cookie
response header. See also this answer on DA.See also the Example 1 in
vcl_deliver
of the example.vcl.Comment #14
abulte CreditAttribution: abulte commentedYou're right, it is working better when testing things from a fresh private browser session.
I'll close this issue since you helped me a lot and I'm now able to cache a lot of stuff. Thank you very much for your very appreciated help.