每小时请求限制

发布于 2024-07-15 06:13:45 字数 83 浏览 4 评论 0原文

如何像 Twitter 一样限制来自一个 IP 的每小时请求? 例如,我想每小时提供 100 个请求。 有什么解决办法吗? 阿帕奇模块? 谢谢。

How to limit requests per hour from one IP like it is in Twitter? For example, I want to provide 100 requests per hour. Is there any solution? Apache modules? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两人的回忆 2024-07-22 06:13:45

从简单开始。

  • 使用 API 密钥的概念(可以说
    它是映射到域或域的 guid
    帐户)。
  • 每次你的 API 被点击时
    键并增加其相应的计数器。
  • 根据您的情况编写限制规则
    计数器(在本例中为小时)
  • 重置。

不建议通过 IP 进行阻止。NAT 是问题所在

Start simple.

  • Use the concept of API keys(Lets say
    its a guid mapped to a domain or an
    account).
  • Every time your API is hit take that
    key and increment its corresponding counter.
  • Write rules to limit based on your
    counter(in this case hours)
  • Reset.

Blocking by IP is not advisable.NAT being the problem

独闯女儿国 2024-07-22 06:13:45

不要通过IP来做到这一点。 整个大学、公司或网吧的人可能共享同一个IP。 最好将具有随机值的 cookie 注入每个客户端的第一个 http 响应中,以识别唯一性。

Don't do it by IP. People from a whole university, company or internet cafe may share the same IP. It's best if you inject a cookie with random value to the first http response for each client in order to identify uniqueness.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文