配置nginx_conf
map $uri $name_8080{
"~*t8080" $uri; ##如果请求uri中匹配t8080,则$name_8080=$uri
}
map $uri $name_8081{
"~*t8081" $uri;
}
limit_req_status 429;
limit_req_zone $name_8080 zone=req_8080:20m rate=5r/s;
limit_req_zone $name_8081 zone=req_8081:20m rate=1r/s;
配置location
location / {
limit_req zone=req_8080;
limit_req zone=req_8081;
proxy_pass http://127.0.0.1:8080/;
}
测试
通过jmeter分别请求http://127.0.0.1:8083/t8080和http://127.0.0.1:8083/t8081测试
http://127.0.0.1:8083/t8080成功率50%
http://127.0.0.1:8083/t8081成功率10%
测试其它uri无限流,符合预期