gpt4 book ai didi

apache - 如何检查是否为Symfony激活了Varnish?

转载 作者:行者123 更新时间:2023-12-03 17:45:33 26 4
gpt4 key购买 nike

我想将Varnish用于Symfony和eZ平台CMS。我已按照本教程设置了Varnish:http://book.varnish-software.com/4.0/chapters/Getting_Started.html#exercise-install-varnish

所以我有以下工作服务器:

  • Varnish在端口80上监听
  • Varnish在localhost:8080上使用后端
  • Apache在本地主机上监听:8080

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

    我将以下两行添加到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服务器的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

    所以我想这是正确的值(value)。
    然后,我在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 header ,并且得到了以下信息:
    Via: "1.1 varnish-v4"
    X-Varnish: "32808"

    我想这是一个不错的进步。
    无论如何,在Symfony探查器中,我仍然具有以下intel:
    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默认缓存的工作方式,因为我已在配置文件中将其禁用。

    感谢您的帮助。

    最佳答案

    如果你看到类似的东西

    Via: "1.1 varnish-v4"
    X-Varnish: "32808"

    你的 Varnish 正在工作。为什么要禁用symfony缓存?您可以同时使用两者...可能有意义,也可能没有意义。这在很大程度上取决于程序逻辑。

    如果您想在开发过程中更深入地了解 Varnish ,可以添加以下几行:
    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;
    }

    关于apache - 如何检查是否为Symfony激活了Varnish?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37654544/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com