nginx+lua+memcache封禁频繁访问ip
来源:互联网 发布:网店淘宝怎么刷信誉 编辑:程序博客网 时间:2024/04/26 06:29
根据网上找的nginx+lua+redis修改
ip_bind_time = 300 --封禁IP时间ip_time_out = 10 --指定ip访问频率时间段 connect_count = 10 --指定ip访问频率计数最大值 --连接memcache local memcached = require "memcached"local cache,err = memcached:new()if not cache then ngx.say("failed to initiall memcached",err) returnend--ngx.say("success to initiall memcached")local ok,err = cache:connect("127.0.0.1",11211)if not ok then ngx.say("failed to connect memcached",err) returnend--ngx.say("success to connect memcached") --查询ip是否在封禁段内,若在则返回403错误代码 --因封禁时间会大于ip记录时间,故此处不对ip时间key和计数key做处理 is_bind , err = cache:get("bind_"..ngx.var.remote_addr) if is_bind == "1" then cache:close() ngx.exit(403); return;end start_time , err = cache:get("time_"..ngx.var.remote_addr) ip_count , err = cache:get("count_"..ngx.var.remote_addr) --如果ip记录时间大于指定时间间隔或者记录时间或者不存在ip时间key则重置时间key和计数key --如果ip时间key小于时间间隔,则ip计数+1,且如果ip计数大于ip频率计数,则设置ip的封禁key为1 --同时设置封禁key的过期时间为封禁ip的时间 if start_time == nil or os.time() - start_time > ip_time_out then res , err = cache:set("time_"..ngx.var.remote_addr , os.time()) res , err = cache:set("count_"..ngx.var.remote_addr , 1) else ip_count = ip_count + 1 res , err = cache:set("count_"..ngx.var.remote_addr,ip_count) if ip_count >= connect_count then res , err = cache:set("bind_"..ngx.var.remote_addr,1,ip_bind_time) end end
阅读全文
0 0
- nginx+lua+memcache封禁频繁访问ip
- nginx+lua+redis自动识别封解禁IP频繁访问
- Nginx 通过 Lua + Redis 实现动态封禁 IP
- nginx 查看访问 IP 并封禁 IP 详解
- Nginx屏蔽访问过于频繁的IP
- Nginx+iptables屏蔽访问Web页面过于频繁的IP(防DDOS,恶意访问,采集器)
- Nginx+iptables屏蔽访问Web页面过于频繁的IP(防DDOS,恶意访问,采集器)
- Nginx+iptables屏蔽访问Web页面过于频繁的IP(防DDOS,恶意访问,采集器)
- Nginx+Lua访问Redis
- asp.net : 拒绝频繁的IP访问
- 利用nginx+lua+memcache实现灰度发布
- 利用nginx+lua+memcache实现灰度发布
- 利用nginx+lua+memcache实现灰度发布
- Nginx 禁止IP访问
- Nginx限制ip访问
- nginx限制IP访问
- nginx 禁止IP访问
- nginx过滤IP访问
- cardview的简单使用
- 2017.5.24并查集小结
- 【tensorflow学习】使用tensorboard实现数据可视化
- c# Invoke和BeginInvoke 区别
- 算法练习-相亲数
- nginx+lua+memcache封禁频繁访问ip
- 金山面试题
- 基础的ajax请求
- 将网页中的相对路径转化为绝对路径
- ffmpeg编译 (3.3版本) 以及 命令行工具的集成
- .Net图片上传
- windows下rudy更换sources之淘宝镜像
- maven 小结学习(一)
- 给retrofit添加拦截器以查看传输的数据