清漆:如果我在 hash_data 中有 cookie,则清除 [英] Varnish: purge if I have cookie in hash_data

查看:17
本文介绍了清漆:如果我在 hash_data 中有 cookie,则清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我无法清除我的页面.很多次之后,我决定找出清除的工作原理并找到!

I couldn't purge my page. After many time I decided to find out how purge works and find!

如您所见,我们使用了一个新操作 - return(purge).这将结束 vcl_recv 的执行并跳转到 vcl_hash.这就像我们处理常规请求一样.当 vcl_hash 调用 return(lookup) varnish 将清除对象,然后调用 vcl_purge.在这里,您可以选择添加任何希望清漆在清除对象后采取的特定操作.文档

As you can see we have used a new action - return(purge). This ends execution of vcl_recv and jumps to vcl_hash. This is just like we handle a regular request. When vcl_hash calls return(lookup) varnish will purge the object and then call vcl_purge. Here you have the option of adding any particular actions you want Varnish to take once it has purge the object. docs

然后我知道我在 hash_data 中有 cookie,我无法清除特定的 url.

And then I understood that I have cookie in hash_data and I can't purge specific url.

问题:

如何通过 URI 清除我的所有页面?我认为禁令系统帮不了我.也许你给我建议?

How can purge all my pages by URI? I think ban system can't help me. Maybe you suggest me something?

推荐答案

Purge 方法仅适用于正在请求的特定 url.不能在 Purge 中使用正则表达式.例如:发出对 www.example.com/uri 的请求并调用 Purge,只有整个 URL 的对象才会从缓存中删除.然后,如果您想使用 Purge,则必须在 VCL 上实现以下功能:

The Purge method will work only for the specific url that is being requested. It is not possible to use regular expressions with Purge. For example: a request for www.example.com/uri is made and a Purge is called, only the object for this whole URL will be removed from cache. Then, if you want to use Purge you will have to implement the following feature on your VCL:

acl purge {
    "localhost";
    "192.168.55.0"/24;
}
sub vcl_recv {
        ...
        # allow PURGE from localhost and 192.168.55...

        if (req.method == "PURGE") {
                if (!client.ip ~ purge) {
                        return(synth(405,"Not allowed."));
                }
                return (purge);
        }
        ...
}

之后,清除 URL 所需要做的就是使用 Purge 方法向您的 Varnish 发送请求,如下所示:

After that, all you need to do to purge an URL is to send a request with the Purge method to your Varnish like this:

$ curl -X PURGE "www.example.com/desired/uri"

当您只想通过一个请求删除多个对象时,可以使用 Ban.这可以使用 Purge 中不可用的正则表达式来完成.为了使用它,你应该有一个类似于下面的代码,维护之前的 acl:

The Ban is used when you want to remove many objects with only one request.This can be accomplished using regular expressions that are not available in Purge. In order to use it you should have a code similar to the one below, maintaining the acl from before:

sub vcl_recv {
        ...
        if (req.method == "BAN") {
                # Same ACL check as above:
                if (!client.ip ~ purge) {
                        return(synth(403, "Not allowed."));
                }
                ban("req.http.host == " + req.http.host +
                      " && req.url ~ " + req.url);

                # Throw a synthetic page so the
                # request won't go to the backend.
                return(synth(200, "Ban added"));
        }
        ...
}

禁止对象类似于清除,但现在您可以发送正则表达式.下面的例子展示了如何禁止来自主机 www.example.com 的所有 png 文件:

To ban objects is similar to purge but now you can send Regex. The example below shows how to ban all png files from the host www.example.com:

$ curl -X BAN "www.example.com/.png$"

所有信息均来自清漆文档.

我希望这个答案可以帮助您了解禁令和清除的工作原理,以及您可以确定它们如何为您提供帮助.

I hope this answer can help you understand how Bans and Purges work and that you can identify how they can help you.

如果有任何遗漏或不能满足您的需求,请编辑您的问题以更清楚地表达您的疑问(标题和问题之间存在分歧,可能会导致混淆),我很乐意编辑回答.

If anything is missing or is not addressing your needs, please edit your question to be clearer in your doubts (there is a divergence between the tittle and the question that may lead to confusion) and I'll be happy to edit the answer.

这篇关于清漆:如果我在 hash_data 中有 cookie,则清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆