Apisix自定义httpcode 请求重试

我们通过插件来做比较麻烦并且还需要考虑重新lb的问题,有一个比较简单的方法是利用nginx的请求重试信号。

Apisix本身默认也有该种设定,不过默认只针对 timeout情况会请求重试

默认请求重试次数是:updateam node 节点数量 -1

相关逻辑在apisix-balancer.luaset_balancer_opts 方法中

设置Nginx配置文件,添加请求重试判断:

我们在 ngx_tpl.lua 760行添加如下配置,示例httpcode可更换
proxy_next_upstream error timeout http_500 http_429 non_idempotent;

支持重试的httpcode可以查看 nginx官方proxy-next-upstream文档

apisix在发生请求重试时,打印的日志中 upstream-statusupstream 会依次将每次请求的结果、上游地址记录出来

相关推荐
NGINX开源社区28 分钟前
将部署从 NGINX Ingress Controller 迁移至 NGINX Gateway Fabric
nginx·gateway·fabric
w***15313 小时前
若依部署Nginx和Tomcat
运维·nginx·tomcat
q***04058 小时前
Nginx 缓存清理
运维·nginx·缓存
这人很懒没留下什么16 小时前
SpringBoot2.7.4整合Oauth2
开发语言·lua
苹果醋317 小时前
VueX(Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式)
java·运维·spring boot·mysql·nginx
q***37517 小时前
Nginx如何实现 TCP和UDP代理?
tcp/ip·nginx·udp
q***965817 小时前
Nginx作用以及应用场景
运维·nginx
q***318320 小时前
Nginx搭建负载均衡
运维·nginx·负载均衡
q***82911 天前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
梁正雄1 天前
linux服务-Nginx+Tomcat+Redis之Session 共享
linux·nginx·tomcat