How can I dynamically change 'rate' attribute value from directive 'limit_req_zone'?

Hello Everyone,

I got to use nginx plus to build a rate limiting solution for my project.

nginx configurations looks like below,


http {

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

server {
    ...

    location /search/ {
        limit_req zone=one burst=5;
    }
}

Project Requirement:

  1. Request rate limiting policy will be maintained by a separate service managing rate limiting policy. e.g. Consumer ‘C’ consumes Service ‘A’ with rate ‘x’ requests per ‘time unit‘.
  2. Application team member is supposed to modify rate limiting policy using a self service model.
  3. As soon as rate limiting policy changes, nginx is supposed to read policy and translate it into equivalent nginx configurations and apply them immediately.
  4. There should not be any downtime while applying new rate-limiting policy.

Below Options Explored:

Option #1: Use nginx plus apis to change nginx rate limiting configurations.

Findings: Nginx plus does not provide any api with which rate can be changes from directive ‘limit_req_zone’

Option #2: Use of nginx java script module to programmatically connect to external source and re-build rate limiting configurations

Findings: It does not seem to be possible to modify rate limiting configurations either.

Option #3: Use nginx-agent to manage nginx plus configurations via control server using http rest api.

Findings: We could successfully could apply latest nginx configurations using a control server by making ‘config apply’ http requests.

Questions:

  1. Is my above understanding correct? feel free to leave your comments.
  2. Is there any other better way to apply configs dynamically ?

Thank you..!

Yeah, I met the similar issue like you.
The main idea of your requirement is that apply new nginx config without downtime, right?
Make a HTTP request API which can update the nginx.config file.
And in the API, please use nginx -t to check if updated nginx.config is valid.
After that, please try nginx -s reload to apply new config immediately.
I hope this guide will be helpful to you.

Thanks

1 Like

Thanks for your feedback..! could you provide me the api endpoint and other details that allows us to change nginx.conf file..? Current nginx api does not exposes any endpoint as such.

Hey all! There is indeed no way to dynamically change any value within limit_req. You can find the available API endpoints here Module ngx_http_api_module

Like you mentioned in Option 3, you might be able to use the NGINX Agent or a configuration management tool such as the Ansible NGINX config role.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.