如何合并这两个清漆后端?

时间:2019-06-21 03:40:41

标签: varnish varnish-vcl thumbor

我正在使用thumbor和s3。

我想在它们前面使用清漆。

我知道如何将清漆放入每个清漆中,但是我无法将两者结合在一起

用于拇指笔的清漆设置

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 个答案:

答案 0 :(得分:0)

您应该将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