清漆:使缓存依赖于X-Forwarded-Proto https [英] Varnish: Make cache dependent on X-Forwarded-Proto https
问题描述
以下情况:
在服务器上是一个用于缓存的apache和Varnish。 SSL由亚马逊负载均衡器处理。
如果使用https请求页面,则会将http标题X-Forwarded-Proto设置为https。
这些页面有时是不同的(例如,当使用安全连接时,必须使用https获取链接/图像)
following situation: On the server is a apache and Varnish for caching. SSL is handled by an amazon load balancer. If the page is requested using https, the http header "X-Forwarded-Proto" is set to "https". The pages are sometimes different (e.g. links/images have to be fetched using https when using a secure connection)
如何判断页面是否不同如果X-Forwarded-Proto标题不同?
现在,无论先访问哪个缓存,然后为http和https服务!
How can I tell varnish that pages are different if the X-Forwarded-Proto header differs? As it is now, whatever is accessed first is cached and served for http and https!
推荐答案
,我认为,应该有不同的缓存版本的相同的URI,这很容易使用自定义 vcl_hash
:
What you want, I presume, is to have different cached versions of the same URI, that's pretty easy using a custom vcl_hash
:
sub vcl_hash {
# ...
if (req.http.X-Forwarded-Proto &&
req.url !~ "(?i)\.(png|gif|jpeg|jpg|ico|gz|tgz|bz2|tbz|mp3|ogg|zip|rar|otf|ttf|eot|woff|svg|pdf)$") {
hash_data(req.http.X-Forwarded-Proto);
}
# ...
}
在这个例子中静态文件只缓存一次,其余的(html,js,css ..)缓存在两个不同的版本中(假设X-Forwarded-Proto只有两个值)。
In this example static files are only cached once and the rest (html, js, css..) are cached in 2 different versions (assuming X-Forwarded-Proto only takes two values).
您可以在 https ://github.com/NITEMAN/varnish-bites/blob/master/varnish3/drupal-base.vcl
这篇关于清漆:使缓存依赖于X-Forwarded-Proto https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!