HAProxy在出现404错误时重试请求到不同的后端。

huangapple go评论69阅读模式
英文:

HAProxy retry request on a different backend on 404

问题

我正在尝试让HAProxy在不同后端出现404错误时重试请求。

我运行了2个S3实例,想要从中获取一个对象。

情况是,如果“s3Primary”存储桶中的数据不存在并返回404错误,我想能够使用相同的请求查询“s3Secondary”存储桶。

frontend app
    bind *:80
    acl not_found status 404
    use_backend s3Secondary if not_found
    default_backend s3Primary

backend s3Primary
    server s3prime 127.0.0.1:9001

backend s3Secondary
    server s3second 127.0.0.1:9002

我尝试使用http-response进行重定向,但请求仅挂起而不解析。我还在这个问题中看到了答案。

目前的解决方案仅返回404错误,我对HAProxy还很陌生。

英文:

I’m trying to get HAProxy to retry a request that 404'd on a different backend.

I am running 2 s3 instance that I want to get an object from,

The scenario is that data in bucket “s3Primary” will not exist and returns 404 I want to be able to query bucket “s3Secondary” with that same request.

frontend app
    bind *:80
    acl not_found status 404
    use_backend s3Secondary if not_found
    default_backend s3Primary

backend s3Primary
    server s3prime 127.0.0.1:9001

backend s3Secondary
    server s3second 127.0.0.1:9002

I have tried redirecting using http-response but the request just hangs without resolving I have also seen the answer in this question

Currently the solution just returns 404, I'm new to haproxy.

答案1

得分: 1

HAProxy有一个出色的机制,可以在最坏的情况下或称为failover能力的情况下处理事务。要实现类似的功能,您可以尝试在同一后端使用关键字backup。以下是一个示例。

frontent app
 bind *:80
 default_backend s3_backend

backend s3_backend
 server s3_primary   127.0.0.1:9001 check
 server s3_secondary 127.0.0.1:9002 check backup

您还可以将多个备份添加为备份位置,但需要添加类似于这样的内容。

backend s3_backend
 option allbackups
 server s3_primary   127.0.0.1:9001 check
 server s3_secondary 127.0.0.1:9002 check backup
 server s3_verybad   127.0.0.1:9003 check backup

或者,您也可以通过添加访问控制列表中的条目来进行类似的操作。

frontent app
 bind *:80

 acl primary_failed nbsrv(s3_primary) lt 1

 use_backend s3_secondary if primary_failed

 default_backend s3_primary

backend s3_primary
 server s3_primary   127.0.0.1:9001 check

backend s3_secondary
 server s3_secondary 127.0.0.1:9002 check

希望这有所帮助。

英文:

HAProxy has a great mechanism to take of things when a worst case happens or something called as failover capabilities. To achieve something like that you can try using a keyword backup in the same backend. Here is an example.


frontent app
 bind *:80
 default_backend s3_backend

backend s3_backend
 server s3_primary   127.0.0.1:9001 check
 server s3_secondary 127.0.0.1:9002 check backup

You can also add multiple backups as your backup locations, but you need to add something like this


backend s3_backend
 option allbackups
 server s3_primary   127.0.0.1:9001 check
 server s3_secondary 127.0.0.1:9002 check backup
 server s3_verybad   127.0.0.1:9003 check backup

Or you can also do it similar way how you did by adding an entry to access-control list


frontent app
 bind *:80

 acl primary_failed nbsrv(s3_primary) lt 1

 use_backend s3_secondary if primary_failed

 default_backend s3_primary

backend s3_primary
 server s3_primary   127.0.0.1:9001 check

backend s3_secondary
 server s3_secondary 127.0.0.1:9002 check

Hope this helps.

huangapple
  • 本文由 发表于 2020年1月3日 19:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定