当前位置:网站首页>巧用ngx_lua做流量分组
巧用ngx_lua做流量分组
2022-07-28 09:56:00 【InfoQ】
背景
- 测试环境并行测试:一个服务有多个需求同时进行测试,需要nginx根据特定信息将流量转发到指定测试机。
- 全链路压测:流量无区分,影响线上用户,只能在业务低峰进行压测,需要值守,成本较高,需要能够流量隔离,随时可以进行压测。
- 灰度发布:需要nginx根据指定信息将流量转发到指定的灰度机器上。
ngx_lua模块

ngx_lua 运行指令
设置流量标签
方式一:

...
if (tag == "" or checkTag(host_pass, tag) == false)
then
return host_pass;
end
...
return host_pass.."_"..tag;
set_by_lua_file $host_pass set_tag.lua;
方式二:

...
local host = ngx.var.host
local hostList = split(host, ".")
local subDomain = split(hostList[1], "-")
...
ngx.req.set_header("global-route-tag", subDomain[2])
ngx.header["global-route-tag"] = subDomain[2]
...
local test_host = ipList[1].."."..hostList[2].."."..hostList[3]
return test_host
set_by_lua_file $test_host set_test_servers.lua ;
location / {
...
proxy_pass http://$host_pass;
proxy_set_header Host $test_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
结合dyups上下线带标签服务
实现效果

总结
- WEB应用防火墙(waf);
- 限流;
- 降级;
- 服务质量监控。
关于作者
边栏推荐
- PHP7 中 ?? 与? :的区别
- (十)defer关键字
- LSA and optimization of OSPF
- 13 probability distributions that must be understood in deep learning
- 博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
- MySQL 为什么有时候会选错索引?
- _HUGE and __IMP__HUGE in “math.h“
- Thinking and summary of technical personnel | R & D Efficiency
- uni-app进阶之创建组件/原生渲染
- [OpenHarmony] [RK2206] 构建OpenHarmony编译器 (二)
猜你喜欢

Illustrate three mainstream enterprise architecture models (recommended collection!)
![[ESP32][esp-idf] AP+STA实现无线桥接 中转wifi信号](/img/bf/0a968064a8f7c11b86a2a2820208e6.png)
[ESP32][esp-idf] AP+STA实现无线桥接 中转wifi信号

【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03

OSPF的拓展配置,选路原则,防环及重发布

深度学习必懂的 13 种概率分布
![[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?

Thinking and summary of technical personnel | R & D Efficiency

TCP Basics

ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
随机推荐
In retaliation for the dismissal of the company, I changed all code comments of the project!
手机号,固话正则表达式
网易笔试之不要二——欧式距离的典型应用
为什么要考一级建造师,一建证书含金量有多高?
Bit.store, which has attracted much attention, is at a glance of the latest developments
ES(8.1)认证题目
7.27 minimum spanning tree phased test problem solution
OSPF的不规则区域,LSA和序列号
LandingSite电子标签Quuppa固件进入DFU状态说明
广州地铁14号线新市墟站开建,白云区居民即将开启双线换乘模式!
3 minutes to tell you how to become a hacker | zero foundation to hacker getting started guide, you only need to master these five abilities
In the era of home health diagnosis, Senzo creates enhanced lateral flow test products
Status Notice ¶
(十)defer关键字
02.1.2.逻辑类型 bool
13 probability distributions that must be understood in deep learning
关于软考高级要不要报班学习
[esp32][esp idf] esp32s3 quickly build lvglv7.9
office2013以上输入数学公式
ES (8.1) certification topic