我想为Symfony和我的eZ平台CMS.I使用漆。我遵循本教程来设置我的Varnish:Started.html#exercise-install-varnish
因此,我有以下工作服务器:
我还设置了我的eZ平台ezplatform.yml和ezplatform.conf,以禁用默认缓存并启用清漆(我猜)。
我在ezplatform.conf中添加了这两行,以跟踪文档https://doc.ez.no/display/TECHDOC/Using+Varnish:
SetEnv USE_HTTP_CACHE 0
SetEnv TRUSTED_PROXIES "0.0.0.0"我将0.0.0.0用于Varnish地址,因为netstat -nlpt为Varnish提取了以下地址:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 11151/varnishd
tcp 0 0 127.0.0.1:1234 0.0.0.0:* LISTEN 11151/varnishd 所以我想这是正确的价值。然后,我在ezplatform.yml中添加了以下行(查看上面的文档):
ezpublish:
http_cache:
purge_type: http
siteaccess:
list: [site]
groups:
http_cache:
purge_servers: 0.0.0.0:80清漆和httpd重新启动良好。然后,我检查了本地网站是否使用了Varnish,检查了HTTP标头,得到了如下结果:
Via: "1.1 varnish-v4"
X-Varnish: "32808"我想这是一个很好的进步。总之,在Symfony分析器中,我仍然有以下情报人员:
Cache Information
Default Cache default
Available Drivers Apc, BlackHole, FileSystem, Memcache, Redis, SQLite
Total Requests 349
Total Hits 349
Cache Service: default
Drivers FileSystem
Calls 349
Hits 349
Doctrine Adapter false
Cache In-Memory true还能拿到这个是正常的吗?它不应该是类似默认缓存:清漆而不是默认吗?我如何检查我的清漆目前是否在我的网站上工作,而不是symfony默认缓存?
顺便说一下,这是我的vcl文件:
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.
# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;
import directors;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_init {
new backs = directors.hash();
backs.add_backend(default, 1);
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
set req.http.X-cookie = req.http.cookie;
if (!req.http.Cookie ~ "Logged-In") {
unset req.http.Cookie;
}
if (req.url ~ "\.(png|gif|jpg|png|css|js|html)$") {
unset req.http.Cookie;
}
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}
sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}即使没有完成,我也不知道Symfony默认缓存是如何工作的,因为我已经在配置文件中禁用了它。
谢谢你的帮助。
发布于 2016-06-09 18:13:23
如果你看到这样的事情
Via: "1.1 varnish-v4"
X-Varnish: "32808"你的漆起作用了。为什么禁用symfony缓存呢?你可以同时使用..。可能说得通也可能说不通。这在很大程度上取决于程序逻辑。
如果您想在开发过程中对您的清漆有更深入的了解,可以添加以下几行:
sub vcl_deliver {
if (obj.hits > 0) { # Add debug header to see if it's a HIT/MISS
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
# show how ofthe the object created a hit so far (reset on miss)
set resp.http.X-Cache-Hits = obj.hits;
}https://stackoverflow.com/questions/37654544
复制相似问题