负载均衡器后面的 Varnish 不缓存内容
我正在使用此行删除 default.vcl
中的 cookie 以允许 Varnish 缓存,
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|__utma_a2a|has_js|Drupal.toolbar.collapsed|MNO_abc_qrst_\d+)=[^;]*", "");
但它似乎不起作用。
Varnish 位于负载均衡器后面,负载均衡器设置一个持久性 cookie,该 cookie 以这种格式出现在标头中:
Set-Cookie:MNO_abc_qrst_80=aaaaaaaaa2a5882045525d5a4a58455e445a4a423660;expires=Fri, 12-Aug-2011 17:23:23 GMT;path=/;httponly
我在模拟器中运行了这个正则表达式,它捕获了上面的行(直到第一个“;”)。所以我认为这个正则表达式应该捕获它,但它似乎没有捕获它?当我绕过此负载均衡器时,内容会被缓存。
有什么想法吗?我缺少什么?
I am using this line to remove cookies in default.vcl
to allow for Varnish caching
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|__utma_a2a|has_js|Drupal.toolbar.collapsed|MNO_abc_qrst_\d+)=[^;]*", "");
but it does not appear to work.
Varnish is behind a load balancer, the load balancer sets a persistence cookie that appears in this format in the header:
Set-Cookie:MNO_abc_qrst_80=aaaaaaaaa2a5882045525d5a4a58455e445a4a423660;expires=Fri, 12-Aug-2011 17:23:23 GMT;path=/;httponly
I ran this regex in an emulator and it catches the above line (until the first ";"). So I'd think this regex should catch it, but it doesn't appear to? When I bypass this load balancer, content gets cached.
Any ideas? What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以选择,要么验证需要删除整行,
或剪掉该线的有问题的部分。我不知道你使用的是哪种正则表达式引擎。为了获得更好的结果,至少需要进行负面的回顾和反向参考。
压缩验证:
/^(?=(Set-Cookie:\s*))(?:\1|.*?;\s*)(?:__[az]+|__utma_a2a|has_js|Drupal\.toolbar\ .collapsed|MNO_abc_qrst_\d+)=[^;]*(?:;|$).*$/s
压缩的全局部分替换:
s/(?:(?<=^Set-Cookie:)|(?<=;))\s*(?:__[az]+|__utma_a2a|has_js|Drupal\.toolbar\. Collapsed|MNO_abc_qrst_\d+)=[^;]*(?:;|$)//g
正则表达式的扩展视图(在 Perl 中):
输出:
There are 2 ways to go, either validate the entire line needs to be removed,
or cut out the offending parts of the line. I don't know what kind of regex engine you are using. At least negative look behinds and back references are necessary for a better result.
Compressed validation:
/^(?=(Set-Cookie:\s*))(?:\1|.*?;\s*)(?:__[a-z]+|__utma_a2a|has_js|Drupal\.toolbar\.collapsed|MNO_abc_qrst_\d+)=[^;]*(?:;|$).*$/s
Compressed global part substitution:
s/(?:(?<=^Set-Cookie:)|(?<=;))\s*(?:__[a-z]+|__utma_a2a|has_js|Drupal\.toolbar\.collapsed|MNO_abc_qrst_\d+)=[^;]*(?:;|$)//g
An expanded look at the regex's (in Perl):
Output: