How does nginx implement read write current limiting methods
- 2020-05-12 06:59:39
- OfStack
Read/write current limits for nginx
Some time ago, an api was developed for external call. The leader said to limit the current and request a single IP, 50 reads and 10 writes per second
Universal nginx, a few lines of configuration
# So you define the rules, you write them down server outside
limit_req_zone $binary_remote_addr $uri zone=api_write:20m rate=10r/s; # write
limit_req_zone $binary_remote_addr $uri zone=api_read:20m rate=50r/s; # read
# Apply the above rules to interfaces that require speed limits
# write 10/ seconds
location = /api/v1/trade {
limit_req zone=api_write burst=10;
proxy_pass http://api_server;
}
# The query 50/ seconds
location /api/v1/query {
limit_req zone=api_read burst=50;
proxy_pass http://api_server;
}
nginx -s reload
Again, the application doesn't need to care, not a single line of code is touched
Thank you for reading, I hope to help you, thank you for your support of this site!