Rails 实现统计单位时间内 (1 秒) 用户请求数量,以此来屏蔽爬虫?

ayumi043 · July 19, 2012 · Last by ayumi043 replied at July 20, 2012 · 3810 hits

现在思路是,直接在 ApplicationController before_filter 用 session 保存用户 ip,访问次数。但是在 ApplicationController 或 before_filter 里无法获取到 session,或者用 redis 来记录而不用 session。 请教一下各位大大或者有没有什么思路!

不知道 nginx 的这个 module 是不是满足你的需求 http://wiki.nginx.org/HttpLimitReqModule

肉饼以前写过一篇这个的 http://robbin.iteye.com/blog/451014

before_filter 可以拿 session,不过 session 不适合储存这个数据,爬虫可以丢弃 cookies。

用 redis 来做 ip 计数。

不用这么复杂,nginx 的模块搞定

limit_req_zone Limit frequency of connections from a client. This module allows you to limit the number of requests for a given session, or as a special case, with one address. Restriction done using leaky bucket.

#1 楼 @allenwei 好东西,接下来就试试

感谢楼上几位的回答。看来我的思路还是太窄了。 #1 楼 ,#2 楼 提供的思路,都是从日志方面入手。

You need to Sign in before reply, if you don't have an account, please Sign up first.