2

我有一个网站 www.mysite.com 在负载均衡器后面运行。负载均衡器集群中有两台服务器。每个都运行 Varnish 3.0 和 Apache/PHP(我知道 varnish 可以为我实现负载平衡——但我们偏爱不同的 LB 技术)。

时不时地我需要清除一个或两个 URL...

在我的 VCL 中,我将 127.0.0.1 作为 PURGE 的可信 URL。和一个标准的清除配置:

vcl_recv:

....

    if (req.request == "PURGE") {

        # Allow requests from trusted IPs to purge the cache

        if (!client.ip ~ trusted) {

           error 405 "Not allowed.";

        }

        return(lookup); # @see vcl_hit;

    }

...

子 vcl_hit {

if (req.request == "PURGE") {

    purge;

    error 200 "Purged (via vcl_hit)";

}



if (!(obj.ttl > 0s)) {

    return (pass);

}



return (deliver);

}

子 vcl_miss {

if (req.request == "PURGE"){

    purge;

    error 404 "Not in Cache";

}

return (fetch);

}

现在从 shellscript 我想使 URL 无效。

curl -X PURGE http://127.0.0.1/product-47267.html

不起作用,但是

curl -X PURGE http://www.mysite.com/product-47267.html

行得通。这里的问题是 - 我需要在集群中的每台本地机器上失效 - 没有请求通过负载平衡器发出和返回(因为我不知道哪台机器将进行 PURGE)。

希望这是有道理的

长宽

4

1 回答 1

3

你需要连接到localhost但 Varnish 仍然需要知道你想要清除哪个主机。

我不确定,但请尝试以下操作:

curl -X PURGE -H "Host: www.mysite.com" http://127.0.0.1/product-47267.html
于 2012-11-13T20:47:41.160 回答