【问题标题】:What is wrong with my VCL (varnish file). I am trying to use a VMOD我的 VCL(清漆文件)有什么问题。我正在尝试使用 VMOD
【发布时间】:2021-08-02 17:07:45
【问题描述】:

我的 VCL:

vcl 4.1;
import redis;
import std;
# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "2015";
}

sub vcl_init {
    # VMOD configuration: simple case, keeping up to one Redis connection
    # per Varnish worker thread.
    new db = redis.db(
        location="127.0.0.1:6379",
        type=master,
        connection_timeout=500,
        shared_connections=false,
        max_connections=1);
   
    db.command("SET");
    db.push("foo");
    db.push("10s");
    db.execute();
}

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
    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.
    if ( bereq.url ~ " \.(ts|m3u8)$") {
        unset beresp.http.set-cookie;
        # set beresp.http.cache-control = "public, max-age=259200";
        db.command("GET");
        db.push("foo");
        db.execute(false);
    std.log("HERE" + db.get_string_reply());
    set beresp.ttl = std.duration(db.get_string_reply(), 60s);
    return (pass);
    }
}

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.
}

我正在尝试使用 redis vmod。

问题:如您所见,我已使用 redis 将 ttl 逻辑放入 vcl 中。 但是每当我点击 url 时,varnish 总是在内容上使用 120 秒的默认 ttl。

我做错了什么?

【问题讨论】:

    标签: varnish


    【解决方案1】:

    我想通了。这是因为正则表达式本身是错误的。我不知道其中的原因,但这是有道理的。 Varnish 默认为 TTL,因为我遇到的模式在 VCL 中没有进行任何处理,因为我认为正确的正则表达式显然不是。

    因此,默认值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-11
      • 2012-01-14
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2016-01-24
      相关资源
      最近更新 更多