首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查清漆是否被激活为Symfony?

如何检查清漆是否被激活为Symfony?
EN

Stack Overflow用户
提问于 2016-06-06 10:00:06
回答 1查看 1.2K关注 0票数 2

我想为Symfony和我的eZ平台CMS.I使用漆。我遵循本教程来设置我的Varnish:Started.html#exercise-install-varnish

因此,我有以下工作服务器:

  • 清漆监听端口80
  • 清漆在本地主机上使用后端:8080
  • Apache侦听本地主机:8080

我还设置了我的eZ平台ezplatform.yml和ezplatform.conf,以禁用默认缓存并启用清漆(我猜)。

我在ezplatform.conf中添加了这两行,以跟踪文档https://doc.ez.no/display/TECHDOC/Using+Varnish

代码语言:javascript
复制
SetEnv USE_HTTP_CACHE 0 
SetEnv TRUSTED_PROXIES "0.0.0.0"

我将0.0.0.0用于Varnish地址,因为netstat -nlpt为Varnish提取了以下地址:

代码语言:javascript
复制
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中添加了以下行(查看上面的文档):

代码语言:javascript
复制
ezpublish:
    http_cache:
        purge_type: http
    siteaccess:
        list: [site]
        groups:
            http_cache:
              purge_servers: 0.0.0.0:80

清漆和httpd重新启动良好。然后,我检查了本地网站是否使用了Varnish,检查了HTTP标头,得到了如下结果:

代码语言:javascript
复制
Via: "1.1 varnish-v4"
X-Varnish: "32808"

我想这是一个很好的进步。总之,在Symfony分析器中,我仍然有以下情报人员:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
#
# 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默认缓存是如何工作的,因为我已经在配置文件中禁用了它。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2016-06-09 18:13:23

如果你看到这样的事情

代码语言:javascript
复制
Via: "1.1 varnish-v4"
X-Varnish: "32808"

你的漆起作用了。为什么禁用symfony缓存呢?你可以同时使用..。可能说得通也可能说不通。这在很大程度上取决于程序逻辑。

如果您想在开发过程中对您的清漆有更深入的了解,可以添加以下几行:

代码语言:javascript
复制
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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37654544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档