最近发现不知什么原因,匿名用户访问的页面都返回varnish miss,这样造成后台的访问压力非常大。经过几天的debug,总算把问题解决了。下面是问题的总结。
[How to isolate the issue]
If you see the normal anonymous page, it’s HTTP Header always show ‘Cache-Control: public, max-age=xxx’, and can see ‘X-Cache:Hit’.
For the problem page, header will be ‘Cache-Control: no-cache,must-revalidate,post-check=0,pre-check=0’, also first access can see ‘Set-Cookie: SESSxxx=xxx’.
If drupal7 session cookie exists, following request will always miss cache.
[Reason]
For varnish, it depends on apache’s response to determine whether a request will be cached. If apache response header contains ‘Cache-Control: public max-age=xxx’, it will be cached for max-age. If header contains ‘Cache-Control: no-cache’, it will always pass the request to apache.
For anonymous user, drupal7 will not start session by default. This is for performance consideration. If session exists, drupal7 will always return no cache header and drop a session cookie.
But if any data put into $_SESSION, the user session will be started. Dive into the code, in common.inc, function drupal_page_footer will call session.inc’s function drupal_session_commit(). It will check if any data in $_SESSION then call drupal_session_start() to start a session.
If some errors in template, the error string will put into $_SESSION, then drupal7 will start the session.
drupal7+varnish: varnish总是miss的原因
最新推荐文章于 2019-10-12 23:17:36 发布
本文详细介绍了如何解决Drupal 7网站中匿名用户访问导致Varnish缓存失效的问题。通过分析Varnish与Drupal 7之间的交互,我们发现了在没有session的情况下,Drupal 7会始终返回no-cache头部并丢弃session cookie。当模板中出现错误,错误字符串被放入$_SESSION时,Drupal 7会开始session操作,从而导致所有匿名访问都返回varnishmiss。文章提供了解决方案,帮助开发者理解并解决这一问题。
901

被折叠的 条评论
为什么被折叠?



