清漆没有caching有会话的网站

我尝试curl -I domainname ,这里是响应。

 HTTP/1.1 200 OK Date: Tue, 21 Apr 2015 14:49:09 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Set-Cookie: PHPSESSID=kpgqqefkge38jlqc608hq12046; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Type: text/html; charset=UTF-8 X-Varnish: 294982 Age: 0 Via: 1.1 varnish-v4 Content-Length: 0 Connection: keep-alive HTTP/1.1 200 OK Date: Tue, 21 Apr 2015 14:49:10 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Set-Cookie: PHPSESSID=onqvu51sggp70nla7ke5scgr61; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Type: text/html; charset=UTF-8 X-Varnish: 163920 Age: 0 Via: 1.1 varnish-v4 Connection: keep-alive HTTP/1.1 200 OK Date: Tue, 21 Apr 2015 14:49:10 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Set-Cookie: PHPSESSID=s8sd6qufhjl9ki0dh8jc2nb206; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Type: text/html; charset=UTF-8 X-Varnish: 294985 Age: 0 Via: 1.1 varnish-v4 Content-Length: 0 Connection: keep-alive 

以上回应有以下观察:

  1. PHPsessionID值在每个HIT都会不断变化。

  2. 清漆年龄值保持为0。 这意味着该网站不被挖空?

我有一个需要使用会话的网站。 因为用户被允许login,他们的细节保持在会话中。

任何方式如何使网站得到由Varnishcaching? 谢谢!

您必须禁用PHP的会话自动启动,并且只有在用户login时才启动会话。这样PHP不会为未login的用户设置PHPSESSID cookie,从而让Varnishcaching这些页面。