php - Varnish 不仅仅适用于一个网站

标签 php mysql apache server varnish

我有一台有更多站点的服务器,安装 Varnish 后我测试了缓存是否工作,但对于一个网站 Varnish 不起作用(响应 max-age=0)。如果我尝试在该网站的同一文件夹中插入一个简单的 php 页面(与主网站不相关),则响应有效。

这是尝试时的标题:

HTTP/1.1 200 OK
Server: Apache/2.2.27 (Unix) mod_ssl/2.2.27 OpenSSL/1.0.1e-fips
X-Powered-By:   PHP/5.2.17
Set-Cookie: PHPSESSID=ragejao4sm1kckjn1trvap3ft0; path=/
Vary:   User-Agent,Accept-Encoding
Content-Encoding:   gzip
Content-Type:   text/html
Cache-Control:  max_age=8600
magicmarker:    1
Content-Length: 11863
Accept-Ranges:  bytes
Date:   Fri, 12 Jun 2015 12:28:15 GMT
X-Varnish:  1250916100
Age:    0
Via:    1.1 varnish
Connection: keep-alive

最佳答案

默认情况下,Varnish 不会缓存设置了 cookie 的响应。

如果您想更改此行为,您需要考虑 cookie 的使用方式(它看起来像 session cookie),并且使用 session id 作为缓存哈希的一部分(即,这样其他用户就不会得到缓存来自其他人 session 的响应)或使用 ESI 之类的东西来允许缓存页面的“公共(public)”部分,同时独立获取 session 特定部分。

http://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies

https://www.varnish-cache.org/trac/wiki/ESIfeatures

关于php - Varnish 不仅仅适用于一个网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30803122/

相关文章:

apache - Coldfusion 11 REST 服务适用于 HTTP 但不适用于 HTTPS (404)

如果在循环中执行,phpcurl 将返回 400 Bad Request

php - 绑定(bind)准备好的结果不返回输出

MySQL 将货币值更新为 'consumer friendly'

Apache 和 mod_rewrite : Redirect domain to subdirectory

apache - Xampp Apache 服务未启动

php - 在空白窗口中打开数据库提供的链接

php - Laravel 迁移期间的段错误

php - 多个 PHP IF 语句;寻找一种方法来收紧我的代码

foreign-keys - 错误 1452 (23000) : Cannot add or update a child row