我试图让Varnish用博客缓存两个不同的域名,但在添加第二个域名时,前一个域名停止工作,
基本设置如下:
backend default {
.host = "127.0.0.1";
.port = "81";
}
backend onedomain {
.host = "127.0.0.1";
.port = "81";
}
backend newdomain {
.host = "127.0.0.1";
.port = "81";
}
acl purge {
"localhost";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
#Bypass large files
if (req.http.x-pipe-mark && req.restarts > 0) {
return(pipe);
}
# all domains in here will return a "pass" which means they won't be cached
if (req.http.host ~ "(www\.)?(domain1.com|domain2.com)") {
return (pass);
}
#else check if something we're going to cache
else if(req.http.host ~ "(www\.)?(onedomain.nu)") {
set req.http.host = "onedomain.com";
set req.backend_hint = onedomain;
}
else if(req.http.host ~ "(www\.)?(newdomain.com)") {
set req.http.host = "newdomain.com";
set req.backend_hint = newdomain;
}
else {
return (pass);
}
Newdomain加载正常,而domain4只是将我发送到无限重定向循环(根据chrome错误)
我在pastebin中添加了完整配置:http://pastebin.com/J1Hb76dZ
我意识到Varnish本身并没有发送任何重定向命令,该网站适用于旧配置,只有当我尝试这样做才会在其中一个网站上出现重定向问题。
是否有人有这方面的经验,可以建议做什么?
答案 0 :(得分:0)
旧问题,但尝试修改vcl_hash子例程。这适用于我在一个网站上,其中包括多个重定向的http - > https和domain.com - > www.domain.com。它还应该配置散列以区分不同的域,因为这对我来说必须存储与导致可怕的“重定向过多”错误的站点数据分开的所有重定向。您可能需要调整/删除X-Forwarded-Proto标头,因为我在负载均衡器后面。
sub vcl_hash {
hash_data(req.http.host);
hash_data(req.url);
hash_data(req.http.X-Forwarded-Proto);
return(hash);
}