Varnish Vcl 用于多个传入和传出端口连接

Varnish Vcl for multiple incoming and outgoing port connections

一段时间以来,我一直在使用 Varnish 缓存解决方案,只要配置与安装后的配置大致相同,一切都运行良好。

但现在我喜欢用 Varnish 做更多的事情。目前我正在为我的服务器使用以下设置:

访问者 -> CloudFlare -> HaProxy -> Varnish(独立服务器) -> Apache2 内容。

我想知道的是我如何能够制作正确的 vcl 脚本来接受假设来自端口 B 上的 ip A 的传入请求并将其重定向到端口 D 上的 ip C。(这不止一次.)

示例:

Default.Varnish 像这样工作得很好:

DAEMON_OPTS="-a :8085,:8087 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,768m"

但是现在关于 Varnish.Default :

backend default_1 { .host = "11.22.333.444"; .port = "8885"; }
backend default_2 { .host = "11.22.333.444"; .port = "8887"; }

我试过这样的事情:

sub vcl_recv {
 if (server.port == 8885) { set req.backend = default_1; }
 if (server.port == 8887) { set req.backend = default_2; }
}

(请注意,这两个请求都会发送到 相同的传出服务器。只是端口不同!)

对 Varnish 有足够了解的人已经知道我想要什么了。我只是喜欢使用 Varnish 来代理基于不同端口的单独 'channels'。

尝试检查 Varnish 绑定端口,而不是后端端口

sub vcl_recv {
 if (server.port == 8085) { set req.backend = default_1; }
 if (server.port == 8087) { set req.backend = default_2; }
}