gpt4 book ai didi

varnish - 如何在varnishncsa中记录所选的Director>后端

转载 作者:行者123 更新时间:2023-12-03 17:47:05 25 4
gpt4 key购买 nike

我有多个后端服务器,我使用导向器在它们之间“轮循”。

有没有一种方法,如果有的话,如何记录使用哪个后端(后端名称或后端主机名)?
上面提到的是将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,下面是更新的代码...
当未命中和“Varnish 缓存”命中时,此代码将打印出后端名称:
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);
}
}

最佳答案

后端名称(即使使用导演)也可以在vcl_fetch上获得,出于调试目的,我通常使用:

sub vcl_fetch {
# ...
set beresp.http.X-Backend = beresp.backend.name;
# ...
}

关于varnish - 如何在varnishncsa中记录所选的Director>后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com