#Nginx根据参数过滤请求
需求:对于特定的请求/aaa/bbb/ccc?username=zhangsan&mobile=18888888888&age=110&gender=1
location ^~/aaa/bbb/ccc {
set $is_matched 0;
if ($args ~* (?:age=)(110|111|112)){
proxy_pass http://127.0.0.1:8084;
set $is_matched 1;
}
if ($is_matched = 0) {
add_header Content-Type 'application/json; charset=utf-8';
return 200 '{"code":"501","message":"error"}';
}
}
只允许age=110|111|112的请求通过,其他参数同样可设置,参考正则过滤规则
其他请求返回json