-
Notifications
You must be signed in to change notification settings - Fork 1
/
ngx_dong.conf
65 lines (62 loc) · 2.39 KB
/
ngx_dong.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
lua_shared_dict limit 10m;
lua_package_path "/opt/molbase.inc/etc/nginx/?.lua;;";
init_by_lua '
local lib = require "lib" --getClientIp
';
server {
listen 80;
server_name dong.molbase.inc;
access_log /opt/molbase.inc/log/nginx/dong.molbase.inc-access.log;
error_log /opt/molbase.inc/log/nginx/dong.molbase.inc-error.log;
#location /demo {
#default_type 'text/html';
#add_header Content-Type "text/html;charset=utf-8";
access_by_lua '
ngx.header.content_type = "text/html;charset=utf-8"
--2,60,3600,84600
local limit = ngx.shared.limit
local key = getClientIp()
local value, flags = limit:get(key)
if value==nil then
value=tostring(os.time())
--value=0
success, err, forcible = limit:add(key,value)
else
--newval, err = limit:incr(key,1)
limit:set(key,value..tostring(os.time()))
end
local v=string.sub(value,-10000)
if string.len(v)>=10000 and os.time()-string.sub(v,1,10)<86400 then --> 一天内限1000次
--if string.len(value)/10>1000 and os.time()-string.sub(value,1,10)<86400 then -- 一天内限1000次
ngx.exit(500)
else
-- ngx.say(value)
ngx.header["X-Dong"] = "86400:1000"
end
local v=string.sub(value,-5000)
if string.len(v)>=5000 and os.time()-string.sub(v,1,10)<3600 then --> 一小时内限500次
ngx.exit(500)
else
-- ngx.say(value)
ngx.header["X-Dong"] = "3600:500"
end
local v=string.sub(value,-500)
if string.len(v)>=500 and os.time()-string.sub(v,1,10)<60 then --> 一分钟内限50次
ngx.exit(500)
else
-- ngx.say(value)
ngx.header["X-Dong"] = "60:50"
end
local v=string.sub(value,-50)
if string.len(v)>=50 and os.time()-string.sub(v,1,10)<2 then --> 一秒钟内限5次
ngx.exit(500)
else
-- ngx.say(v)
ngx.header["X-Dong"] = "2:5"
end
ngx.header["X-Dong"] = os.time()-string.sub(value,1,10)..":"..string.len(value)
--ngx.exit(200)
';
#return 200; #demo
#}
}