我想使用Varnish for Symfony和我的eZ Platform CMS。我已按照本教程设置我的清漆:http://book.varnish-software.com/4.0/chapters/Getting_Started.html#exercise-install-varnish
所以我有以下工作服务器:
Varnish在localhost上使用后端:8080
Apache监听localhost:8080
我还设置了我的eZ平台ezplatform.yml和ezplatform.conf,以禁用默认缓存并启用清漆(我猜)。
我在文档https://doc.ez.no/display/TECHDOC/Using+Varnish中添加了这两行到ezplatform.conf:
SetEnv USE_HTTP_CACHE 0
SetEnv TRUSTED_PROXIES "0.0.0.0"
我把0.0.0.0用于Varnish服务器IP地址,因为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
Varnish和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
仍然可以得到这个吗?它不应该像Default Cache:varnish而不是default?如何检查我的Varnish当前是否在我的网站上运行而不是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默认缓存是如何工作的,因为我已经在配置文件中禁用了它。
感谢您的帮助。
答案 0 :(得分:0)
如果您看到类似
的内容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;
}