使用 PHP 和 PHP 的客户标头漆
我目前正在设置 Varnish (v3),但我想知道是否有人对以下内容有任何建议。
我正在尝试使用 PHP 的 Header() 函数来设置自定义标头,例如 Test: CustomHeader。最终目标是允许 Varnish 提供缓存页面,除非浏览器(在本例中)已将某些内容添加到购物篮中。我想在我的 VCL 配置文件中,我可以执行以下操作:
if (bereq.http.Test ~ "CustomHeader") {
set beresp.ttl = 0s;
return (hit_for_pass);
}
但是,这始终评估为 false\no match。如果我将其设置为
if (bereq.http.Test != "CustomHeader") {
set beresp.ttl = 0s;
return (hit_for_pass);
}
那么 hit_for_pass 总是被触发,这让我相信我的标头设置有问题。我认为这可能是因为由于缓存的整个点而不会设置 PHP 标头,但是检查 varnishlog 中的标头确实显示了客户标头出现,这令人困惑!此外,访问相关页面始终会执行缓存命中。 有人对 Varnish 中的这种标头操作有任何提示\建议吗? 非常感谢 -B
I'm currently working on a Varnish (v3) set up, but I was wondering if anyone had any advice on the following.
I'm trying to use PHP's Header() function to set a custom header, for example, Test: CustomHeader. The ultimate aim is to allow Varnish to serve cached pages UNLESS a browser, in this case, has added something to a shopping basket. I was thinking that in my VCL config file, I can do something like:
if (bereq.http.Test ~ "CustomHeader") {
set beresp.ttl = 0s;
return (hit_for_pass);
}
However, this is always evaluate as false\no match. If I set it to
if (bereq.http.Test != "CustomHeader") {
set beresp.ttl = 0s;
return (hit_for_pass);
}
Then hit_for_pass is always triggered, which leads me to believe there's something amiss with my header setting. I thought it might be because the PHP header won't be set due to the whole point of the cache, but examining the headers in varnishlog DOES show the customer header appearing though, which is confusing! Additionally, accessing the page in question always performs a cache hit.
Does anyone have any tips\advice on this kind of header manipulation in Varnish?
Many thanks
-B
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这样的事情使用自定义标头是一个坏主意。许多代理会删除它们无法识别的标头,因此即使您让它按照您希望的方式工作,您也无法依赖它。
这就是 cookie 的设计目的 - 请使用它们。
setcookie()
document.cookie
req.http.cookie
Using custom headers for something like this is a bad idea. Many proxies will strip headers they don't recognise, so you would not be able to rely on this even if you get it working the way you want it to.
This is what cookies were designed for - use them instead.
setcookie()
document.cookie
req.http.cookie