0

我有 AWS Route53 地理域名和 3 个 AWS 区域,它们具有相同的应用程序但具有不同的客户端。

一些客户端在 Region1 上,一些客户端在 Region2 上,依此类推。

因为来自 Region2 的基于地理的记录客户端无法直接连接到来自 Region1 的客户端,因为它将解析为 Region2 ALB,并且应用程序将响应没有这样的客户端,但它可以使用 Custom_header "X-Region=region1" 和 HTTP/410 进行响应

是否可以在 HAproxy 上设置如下内容:

如果默认后端响应 200(在同一区域中找到客户端),则只需 proxy_pass 并且不检查 X-Region 标头。

如果默认后端 res.hdr(X-Region) -i region1,则使用 backend_region1 作为 proxy_pass

如果默认后端 res.hdr(X-Region) -i region2,则使用 backend_region2 作为 proxy_pass

谢谢。

4

1 回答 1

0

现在我在 Varnish+HAproxy 上实现了:

vcl 4.0;

import directors;
import std;

backend eu-west-1 {
    .host = "127.0.0.1";
    .port = "8080";
}

backend ap-southeast-1 {
    .host = "127.0.0.1";
    .port = "8081";
}

backend ap-southeast-2 {
    .host = "127.0.0.1";
    .port = "8082";
}

sub vcl_recv {
if (req.method == "POST"){ std.cache_req_body(5000KB);}
  set req.backend_hint = eu-west-1;
    if (req.restarts > 0 && req.http.x-region == "ap-southeast-1"){
        set req.backend_hint = ap-southeast-1;
    }
    if (req.restarts > 0 && req.http.x-region == "ap-southeast-2"){
        set req.backend_hint = ap-southeast-2;
    }
  return(pass);
}

sub vcl_deliver {
    if(resp.status == 410 && req.restarts < 1 && resp.http.X-Region == "ap-southeast-1")
    {
        set req.http.x-region = "ap-southeast-1";
       return(restart);
    }
    if(resp.status == 410 && req.restarts < 1 && resp.http.X-Region == "ap-southeast-2")
    {
        set req.http.x-region = "ap-southeast-2";
        return(restart);
    }
}

frontend eu-west-1
        bind *:8080
        use_backend eu-west-1

frontend ap-southeast-1
        bind *:8081
        use_backend ap-southeast-1

frontend ap-southeast-2
        bind *:8082
        use_backend ap-southeast-2

backend eu-west-1
        server eu-west-1 127.0.0.1:90 check
backend ap-southeast-1
        server ALB1:443 check ssl verify none
backend ap-southeast-2
        server ALB2:443 check ssl verify none

但我想知道这是否可以仅使用 HAproxy 来完成。

于 2021-09-21T14:14:51.337 回答