清漆redirect到家庭networking目录

我有一个反向代理,我正在设置一个办公室仪表板,后面有几个networking主机。 最终我想要:

dashboard.company/nagios to go to nagios.company/ dashboard.company/grafana to go to grafana.company/ 

我build立了以下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而不是sourcehost / grafana。 我怎样才能做到这一点?

您需要删除第一层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; } } 

本质上,这意味着/nagios下的所有URL将从nagios后端的根( / )传送,而/grafana下的所有URL将从grafana后端的根( /grafana