我正在使用云数据库服务,具体来说是cloudant,它可以让每个用户通过良好的授权系统直接访问数据库
然而,它也是一项可以很好地扩展并计算每次访问服务器的计费的服务,每 500 次获取请求 0.0015 美元
所以我在考虑任何可以充当代理、CDN 或防火墙的服务,我可以限制每分钟的用户访问频率
例如,如果该用户每分钟发出超过 20 个请求或超过每秒 2 个请求,我想拒绝该用户,这样我可以保护某些用户尝试将请求泛洪到我的服务
有这样的服务吗?它叫什么?你有什么建议吗?
非常感谢
一些 CDN 可能会提供此功能,但您必须联系他们的销售/支持团队或查看文档。但是,如果您可以访问可以安装 nginx 的服务器,它具有请求限制功能,可能完全符合您的要求。
它在“ limit req ”模块中。一些可能适用于您的情况的配置:
http {
limit_req_zone $binary_remote_addr zone=dbzoneip:10m rate=2r/s;
# or limit_req_zone $binary_remote_addr zone=dbzoneip:10m rate=20r/m;
# You can set this up if you want to limit total requests,
# regardless of the incoming IP
limit_req_zone $server_name zone=dbzoneserver:10m rate=100r/m;
# this would be for whatever the path is to the db API
location /db/ {
# now we use it
# check docs to determine if you want to enable bursting
# which allows you to buffer a small number of requests
limit_req zone=dbzoneip;
# comment this out if you just want to limit particular users
limit_req zone=dbzoneserver;
proxy_pass https://url_or_ip_of_cloudant;
}
}