我有多个后端服务器,我使用导演在他们之间“循环”。
有没有办法和 - 如果有 - 如何记录使用哪个后端(后端名称或后端主机名)?
以上是指使用std.log("key:value")
和%{VCL_Log:*key*}x
与varnishncsa。
我的vcl配置:
backend aws_frontend1 {
.host = "aws1.domain.mobi";
.port = "80";
}
backend aws_frontend2 {
.host = "aws2.domain.mobi";
.port = "80";
}
director lb_aws_frontend round-robin {
{
.backend = aws_frontend1;
}
{
.backend = aws_frontend2;
}
}
sub vcl_recv {
set req.backend = lb_aws_frontend;
unset req.http.Cookie;
}
sub vcl_fetch {
if (beresp.http.cache-control ~ "(no-cache|private)" || beresp.http.pragma ~ "no-cache") {
set beresp.ttl = 0s;
} else {
set beresp.ttl = 168h;
}
}
sub vcl_error {
if (obj.status == 750) {
set obj.status = 403;
return(deliver);
}
}
以下是NITEMAN的更新代码...... 当miss和“varnish cache”命中时,此代码打印出后端名称:
import std;
backend aws_frontend1 {
.host = "aws1.domain.mobi";
.port = "80";
}
backend aws_frontend2 {
.host = "aws2.domain.mobi";
.port = "80";
}
director lb_aws_frontend round-robin {
{
.backend = aws_frontend1;
}
{
.backend = aws_frontend2;
}
}
sub vcl_recv {
set req.backend = lb_aws_frontend;
unset req.http.Cookie;
}
sub vcl_fetch {
if (beresp.http.cache-control ~ "(no-cache|private)" || beresp.http.pragma ~ "no-cache") {
set beresp.ttl = 0s;
} else {
set beresp.ttl = 168h;
}
std.log("backend_used:" + beresp.backend.name);
}
sub vcl_hit {
std.log("backend_used:varnish cache");
}
sub vcl_error {
if (obj.status == 750) {
set obj.status = 403;
return(deliver);
}
}
答案 0 :(得分:4)
后端的名称(即使使用了导演)在vcl_fetch
上可用,出于调试目的,我通常使用:
sub vcl_fetch {
# ...
set beresp.http.X-Backend = beresp.backend.name;
# ...
}