【发布时间】:2018-04-07 22:47:02
【问题描述】:
使用 Cloudflare 时,清除似乎不起作用(Cloudflare 返回 403 Forbidden)。
这是我在网上搜索解决方案时得到的:
“问题是,当你使用cloudflare时,varinsh没有得到发送者的原始IP,而是得到了cloudflare的IP。所以无法进行清除。我们需要告诉清漆发送者的原始IP 。”
在 vcl_recv
中添加以下行
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
设置 req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
} 其他 {
设置 req.http.X-Forwarded-For = client.ip;
}
}
if (req.method == "PURGE" || req.url == "/purge") {
# 将这些 IP 替换为您的 IP
if ( req.http.X-Forwarded-For !~ "(209.152.41.21|105.45.120.37)") {
return(synth(405, "此 IP 不允许发送 PURGE
请求。"));
}
ban("req.url ~ /");
返回(清除);
}
我尝试了这个解决方案,但没有奏效。
【问题讨论】:
标签: varnish cloudflare purge