英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论