Set NGINX to 204 for the percentage of incoming requests

I would like to inject incoming requests into the nginx route.

The current configuration is similar to the following:

upstream up0 {
        server x.x.x.x:1111;
        keepalive 1024;
}

server {
        location /auc {
            limit_req   zone=one    burst=2100;
            proxy_pass http://up0/auc;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
        }
}

I would like to control the number of requests that I see on the upstream server. For all other requests, I want nginx to respond with an answer 204.

Also the control over the number of incoming requests will work.

Thanks.

+4
source share
1 answer

Nginx is very effective at limiting queries using limit_req_zone and limit_req.

, . , , IP- , , ip . .

  limit_req_zone key zone=name:size rate=rate;

. , . , , .

  limit_req zone=name [burst=number] [nodelay];

, , 503 (Service Unvailable). , 204 ( ), .

 limit_req_status code;

, 10 , 50 204 :

http {

    ....

    limit_req_zone $hostname zone=limit:20m rate=10r/s;
    limit_req_status 204;

    server {

        ...

        location / {
            ...
            limit_req zone=limit burst=50;

        }

    }
}

, , , http. .

, "" = 10r/m (10 ) . , .

limit_req_zone , , IP- . , .

+4

Source: https://habr.com/ru/post/1616269/


All Articles