nginx限流
2021-05-18 本文已影响0人
一抹圆弧
limit_req_zone 127.0.0.1 zone=one:10m rate=1r/s;
server {
listen 8089;
server_name 127.0.0.1;
location / {
proxy_pass http://127.0.0.1:8081/;
limit_req zone=one burst=1 nodelay;
limit_req_status 400;
error_page 400 = @limit400;
}
location @limit400 {
default_type application/json;
return 200 '{"code":-205,"message":"前方拥挤,请稍后重新提交"}';
}
}
请求:for i in `seq 1 10`; do curl http://127.0.0.1:8089/info; echo ''; done
结果:
{"message":"8081 SVR"}
{"message":"8081 SVR"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}
{"code":-205,"message":"前方拥挤,请稍后重新提交"}