如何在haproxy中只匹配一个特定路径并将请求重定向到后端服务

问题描述 投票:0回答:1

如何将一个特定路径请求重定向到haproxy中的后端服务

下面是我的 haproxy.cfg 文件

global
  log 127.0.0.1   local1
  maxconn 4096
  ssl-default-bind-ciphers TLS13-AES-256-GCM-SHA384:TLS13-AES-128-GCM-SHA256:TLS13-CHACHA20-POLY1305-SHA256:EECDH+AESGCM:EECDH+CHACHA20
  ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11

defaults
  mode http
  maxconn 2048


frontend app1-fe
  bind *:80
  bind *:443 ssl crt /usr/local/etc/haproxy/test.pem
  errorfile 503 /usr/local/etc/haproxy/errors/index.http

  acl app2acl path_beg  /v2
  use_backend app2    if app2acl

  acl app1v2docs path_beg -M /v2/api-docs
  use_backend app1   if app1v2docs

  redirect scheme https if !{ ssl_fc }
  mode http
  timeout connect 5s
  timeout client 5s
  timeout server 5s
  default_backend app1

backend app1
  redirect scheme https if !{ ssl_fc }
  server app1 app1:8080  check inter 5s rise 2 fall 3
 
backend app2  
  server app2 app2:4173  check inter 5s rise 2 fall 3

现在我只想将一个特定端点/路径

(/v2/api-docs)
重定向到/v2/*端点系列/模式的app1以及
/v2
app2
应用程序之后的其余路径/端点。

那么我们如何在 haproxy.cfg 文件中进行特定端点/路径匹配?

haproxy
1个回答
0
投票

订单很重要。第一个匹配规则适用,因此更改它们的顺序。首先更具体的规则:

  acl app1v2docs path_beg /v2/api-docs
  use_backend app1   if app1v2docs

  acl app2acl path_beg  /v2
  use_backend app2    if app2acl

此外,

-M
用于从文件加载地图,所以我想它是不需要的。

© www.soinside.com 2019 - 2024. All rights reserved.