【发布时间】:2016-05-18 01:05:36
【问题描述】:
我在 nging 后面使用 varnish 3 将多个站点代理到一个域中。 基本设置工作正常,但如果文件名已经存在于它的缓存中,我现在遇到清漆提供错误文件的问题。 基本上我在我的 default.vcl 中所做的就是:
if(req.url ~ "^/foo1") {
set req.backend = foo1;
set req.url = regsub(req.url, "^/foo1/", "/");
}
else if(req.url ~ "^/foo2") {
set req.backend = foo2;
set req.url = regsub(req.url, "^/foo2/", "/");
}
如果我现在调用 /foo1/index.html,/foo2/index.html 将提供同一个文件。在重新启动 varnish 并调用 /foo2/index.html 后,/foo1/index.html 将服务于 foo2 的 index.html。
据我所知,这是创建哈希的问题,它不尊重使用的后端,而只尊重 url(缩短后)和域:
11 VCL_call c hash
11 Hash c /index.html
11 Hash c mydomain
我现在通过更改我的 vcl_hash 以也使用后端解决了这个问题,但我确信一定有更好、更方便的方法:
sub vcl_hash {
hash_data(req.url);
hash_data(req.backend);
}
任何提示将不胜感激,非常感谢!
【问题讨论】:
标签: varnish varnish-vcl