【问题标题】: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)

【问题讨论】:

    标签: varnish varnish-vcl thumbor


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 2021-02-24
      • 2018-07-18
      相关资源
      最近更新 更多