[英]Varnish cache according to custom header
I am using Varnish to serve a website but need to have the caching dependent on Geo location. 我正在使用Varnish服务网站,但需要根据地理位置来进行缓存。 I have written a small Vmod that uses Ip2Location to set a request header that has the country code in which is then passed to my application (Magento) via Apache which serves up the relevant content but I need Varnish to also cache depending on the country code.
我编写了一个小的Vmod,它使用Ip2Location设置一个请求标头,该请求标头具有国家/地区代码,然后通过该国家/地区代码通过Apache传递给我的应用程序(Magento),该Apache提供相关内容,但是我还需要Varnish根据国家/地区代码进行缓存。
Is there any way to achieve this? 有什么办法可以做到这一点?
I have sorted this. 我已经排序了。
In the vcl_hash subroutine I needed to add the country code into the hashed data. 在vcl_hash子例程中,我需要将国家/地区代码添加到哈希数据中。
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
hash_data(req.http.X-Country-Code);
return (hash);
}
The default vcl I am using had the whole vcl_hash subroutine commented out because it was using req.hash instead of hash_data() which is no longer available in Varnish 3 so adjust as necessary. 我使用的默认vcl已注释掉整个vcl_hash子例程,因为它使用的是req.hash而不是hash_data(),后者在Varnish 3中不再可用,因此请进行必要的调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.