Nginx通过正文或查询中的参数限制请求?

时间:2017-09-12 13:52:16

标签: http nginx proxy limit

我需要使用包含在body或query参数中的特定参数来限制(GET,POST)请求。如何为此配置NGINX?

当前的nginx配置:

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let circleCenter = touches.first!.location(in: view)
            let circleWidth = CGFloat(25)
            let circleHeight = circleWidth

            let circleView = CircleView(frame: CGRect(x: circleCenter.x, y: circleCenter.y, width: circleWidth, height: circleHeight))
            view.addSubview(circleView)
}

例如 - 请求如下:

override func draw(_ rect: CGRect) { let context = UIGraphicsGetCurrentContext(); context!.setLineWidth(5.0) UIColor.red.set() let center = CGPoint(x: round(frame.size.width)/(2), y: round(frame.size.height)/2) let radius = (round(frame.size.width) - 10)/(2) context!.addArc(center:center, radius:radius, startAngle:0, endAngle:CGFloat(Double.pi) * 2, clockwise:true) context!.strokePath(); }

我需要NGINX来限制每秒param1值的请求。因此,每个具有相同param1的请求应限制为每秒10个。

也许我应该使用openresty呢?

1 个答案:

答案 0 :(得分:0)

limit_req 参数可以在 httpserverlocation 块内,因此传统上您只能限制请求通过路径,例如:

<块引用>

http://localhost:8044/route/path1/path2

但是,只有当访问者点击您的查询字符串键 (param1) 时,才将访问者 ip 映射到变量,然后在 limit_req 指令中使用该 var ($do_limit),例如:

map $arg_ctl    $do_limit {
    "param1"    $binary_remote_addr;
    default     "";
}
limit_req_zone $do_limit zone=mylimit:10m rate=10r/s;
server {
    listen       8044;
    limit_req_log_level warn;
    location /route/{
       limit_req zone=mylimit burst=1000;
       proxy_pass https://the_Cool_server/;
 }}