我有一个反向代理,我正在将其设置为办公室仪表板,其背后有几个网络主机。最终我想要:
dashboard.company/nagios to go to nagios.company/
dashboard.company/grafana to go to grafana.company/
我设置了以下VCL:
backend default {
.host = "127.0.0.1";
.port = "80";
}
backend nagios {
.host = "10.8.1.14";
.port = "80";
}
backend grafana {
.host = "10.8.3.88";
.port = "80";
}
sub vcl_recv {
if (req.url ~ "^/grafana") {
unset req.http.proxy;
set req.backend = grafana;
return (pass);
} elsif (req.url ~ "^/nagios") {
unset req.http.proxy;
set req.backend = nagios;
return (pass);
} else {
set req.backend = default;
}
}
但当我尝试去http://dashboard.company:6081/grafana,它将“grafana”URL 位传递给后端。我希望请求转到源主机 webdir 而不是源主机/grafana。我该怎么做?
答案1
您需要删除第一级 URL,并使用set req.backend_hint
而不是来将请求传递到相应的后端set req.backend
,如下所示:
backend default {
.host = "127.0.0.1";
.port = "80";
}
backend nagios {
.host = "10.8.1.14";
.port = "80";
}
backend grafana {
.host = "10.8.3.88";
.port = "80";
}
sub vcl_recv {
if (req.url ~ "^/grafana") {
unset req.http.proxy;
set req.backend_hint = grafana;
set req.url = regsub(req.url, "^/grafana", "/");
return (pass);
} elsif (req.url ~ "^/nagios") {
unset req.http.proxy;
set req.backend_hint = nagios;
set req.url = regsub(req.url, "^/nagios", "/");
return (pass);
} else {
set req.backend = default;
}
}
本质上,这意味着 下的所有 URL 都将从后端的根()/nagios
传递,并且 下的所有 URL都将从后端的根()传递。/
nagios
/grafana
/
grafana