-
Notifications
You must be signed in to change notification settings - Fork 16
/
nginx.conf
53 lines (43 loc) · 1.31 KB
/
nginx.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
events {
worker_connections 1024;
}
error_log stderr;
http {
resolver 127.0.0.11 ipv6=off;
lua_package_path "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/luajit/share/lua/5.1/?.lua;/lua/src/?.lua";
lua_package_cpath "/usr/local/openresty/lualib/?.so;/usr/local/openresty/luajit/lib/lua/5.1/?.so;";
lua_shared_dict redis_cluster_slot_locks 100k;
init_by_lua_block {
config = {
name = "redis-cluster",
serv_list = {
{ ip = "redis_cluster", port = 7000 },
},
keepalive_timeout = 60000,
keepalive_cons = 1000,
connection_timout = 1000,
max_redirection = 5,
}
redis_cluster = require "resty-redis-cluster"
redis_rate = require "resty-redis-rate"
}
server {
listen 8080;
location /lua_content {
default_type 'text/plain';
# you probably want to use the https://github.com/openresty/lua-nginx-module#access_by_lua phase
content_by_lua_block {
local redis_client = redis_cluster:new(config)
local rate, err = redis_rate.measure(redis_client, ngx.var.arg_token)
if err then
ngx.log(ngx.ERR, "err: ", err)
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
if rate > 10 then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
ngx.say(rate)
}
}
}
}