OpenResty Lua 动态路由与 A/B 测试实践server { listen 80; server_name example.com; location /api/ { content_by_lua_block { local uid = ngx.var.cookie_uid or "" if tonumber(string.sub(uid, -1)) % 2 == 0 then return ngx.exec("/api_v2") else return ngx.exec("/api_v1") end } } location /api_v1 { proxy_pass http://127.0.0.1:7001; } location /api_v2 { proxy_pass http://127.0.0.1:7002; } } 要点基于 Cookie/UA/IP 等特征决定路由目标记录命中与回放,确保切流策略可审计总结Lua 脚本提供灵活的边缘逻辑,适合快速实现 A/B 与灰度路由。

发表评论 取消回复