【问题标题】:varnish exclude url清漆排除网址
【发布时间】:2012-11-02 08:36:55
【问题描述】:

我有一个 varnish 3.xx 服务器,目前可以运行。 Varnish 正在缓存我网站的登录页面。

www.mysite.com/staff

但它可能有不同的 url,具体取决于工作人员的链接,例如

www.mysite.com/staff/index.php?/Tickets/Ticket/View/222200

我的 varnish 配置文件设置如下,以排除缓存员工页面,但它不起作用,因为它正在缓存登录页面,并且在我重新启动 varnish 以清除它的缓存之前它不会登录。

sub vcl_recv {
    # Allow purge only from internal users
    if (req.request == "PURGE") {
        if (!client.ip ~ internal_net) {
            error 405 "Not allowed.";
        }
        return (lookup);

    # Exclude the following
    if (req.url ~ "^/login\.php" ||
      req.url ~ "^/search\.php" ||
      req.url ~ "^/admin(.*)" ||
      req.url ~ "^/admin(.*)" ||
      req.url ~ "^/search(.*)" ||
      req.url ~ "^/visitor(.*)" ||
      req.url ~ "^/staff(.*)" ||
      req.url ~ "^/staff\.php"
    )  {
        return(pass);

    }

    if (req.http.cookie ~ "vb(.*)" ||
        req.http.cookie ~ "bb(.*)" ||
        req.http.cookie ~ "SWIFT_(.*)" ||
        req.url ~ "\?(.*\&)?s=[a-fA-F0-9]{32}(\&|$)" ||
        req.http.cookie ~ "bb_password") {

        return(pass);
    } else {
        unset req.http.cookie;
    }
}

您是否有另一种方法可以排除整个目录并使其不被缓存? IE:来自 /staff 的所有内容,无论其后缀是什么,都不得缓存

【问题讨论】:

    标签: caching varnish


    【解决方案1】:

    排除项应该按照您实现它的方式完美运行。但是,如果您粘贴的代码是您的实际 VCL,则您在 PURGE 部分中有一个打开的 if() 语句。

        sub vcl_recv {
            # Allow purge only from internal users
            if (req.request == "PURGE") {
                    if (!client.ip ~ internal_net) {
                            error 405 "Not allowed.";
                    }
                    return (lookup);
    
    # Exclude the following
    

    应该阅读

        sub vcl_recv {
            # Allow purge only from internal users
            if (req.request == "PURGE") {
                    if (!client.ip ~ internal_net) {
                            error 405 "Not allowed.";
                    }
                    return (lookup);
            }
    
    # Exclude the following
    

    Varnish 不应该接受无效的 VCL,所以如果你的实际 VCL 中不存在错误,请用你的整个 VCL 更新问题。

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 1970-01-01
      • 2018-01-05
      • 2014-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      相关资源
      最近更新 更多