如何合并这两个清漆后端?
Posted
技术标签:
【中文标题】如何合并这两个清漆后端?【英文标题】:How do I merge these two varnish backends? 【发布时间】:2019-06-21 03:40:41 【问题描述】:我正在使用拇指和 s3。
我想在他们面前使用清漆。
我知道如何在它们中分别涂上清漆,但我无法将两者结合起来
thumor 的清漆设置
vcl 4.0;
import directors;
backend thumbor1 .host ="127.0.0.1"; .port="8888"; .max_connections = 200; .connect_timeout = 5s; .between_bytes_timeout = 5s;
# backend thumbor2 .host ="127.0.0.1"; .port="9002"; .max_connections = 200; .connect_timeout = 5s; .between_bytes_timeout = 5s;
acl internal
"localhost";
"127.0.0.1";
sub vcl_init
new vdir = directors.round_robin();
vdir.add_backend(thumbor1);
# vdir.add_backend(thumbor2);
sub vcl_recv
set req.backend_hint = vdir.backend();
if (req.method == "PURGE")
if (!client.ip ~ internal)
return (synth(405, "This IP is not allowed to send PURGE requests."));
return (purge);
if (req.url ~ "\?$")
set req.url = regsub(req.url, "\?$", "");
return (hash);
s3 的清漆设置
vcl 4.0;
backend default
.host = "my.bucket.s3.amazonaws.com";
.port = "80";
sub vcl_backend_fetch
set bereq.http.Host = "my.bucket.s3.amazonaws.com";
set bereq.http.Date = now;
我希望最终结果是这样的
client => varnish => thumbor => s3 (thumbnail image)
client => varnish => s3 (normal image)
【问题讨论】:
【参考方案1】:您应该将 2 个后端块放在一个文件中。然后在 vcl_recv 中,你应该通过一些标题、url 路径等设置你想要的后端。
要设置使用哪个后端,您可以使用:
set req.backend_hint = thumbor1;
# Or
set req.backend_hint = default;
在那里你可以找到我如何应用它来使用 2 个后端 - localhost:3000 & localhost:8080: https://github.com/new-fantastic/vsf-cache-varnish/blob/master/docker/varnish/shared.vcl
【讨论】:
以上是关于如何合并这两个清漆后端?的主要内容,如果未能解决你的问题,请参考以下文章