-
Notifications
You must be signed in to change notification settings - Fork 44
/
proxy.conf
102 lines (87 loc) · 2.48 KB
/
proxy.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
server {
listen 9999;
resolver 233.5.5.5 233.6.6.6 114.114.114.114 valid=3600s;
location ~.*\.(jpg|png|jpeg|gif|js|css|ico)$ {
proxy_pass http://$http_host$request_uri;
}
location / {
allow 222.73.199.34;
deny all;
default_type 'text/plain';
access_by_lua_block {
function conv2str (o)
local rs = ""
if type(o) == "string" then
rs = o
elseif type(o) == "nil" then
rs = "nil"
elseif type(o) == "number" then
rs = tostring(o)
elseif type(o) == "boolean" then
rs = tostring(o)
elseif type(o) == "table" then
for k,v in pairs(o) do
if type(v)=="string" then
rs = rs..k.."="..v.."&"
else
rs = rs..k.."="..conv2str(v).."&"
end
end
if string.find(rs, "&", string.len(rs)-1) ~= nil then
rs = string.sub(rs, 0, string.len(rs)-1)
end
else
error("cannot serialize a " .. type(o))
end
return rs
end
function postargs()
ngx.req.read_body()
local post=""
local args, err = ngx.req.get_post_args() or {}
post=conv2str(args)
return post
end
function logall()
local remote=ngx.var.remote_addr or "-"
local host=ngx.var.http_host or "-"
local nowtime=ngx.var.time_local or "-"
local reqMethod=ngx.req.get_method() or "-"
local reqUri=string.gsub(ngx.var.request_uri, "?.*", "") or "-"
local args=""
local post=""
local headers=ngx.req.get_headers()
local cookies=conv2str(headers["Cookie"])
local useragent=conv2str(headers["User-Agent"])
local header=conv2str(headers)
local line=""
args = conv2str(ngx.req.get_uri_args())
if reqMethod == "POST" then
args = postargs()
end
line = '{"method":"'..reqMethod..'", "host":"'..host..'", "uri":"'..reqUri..'", "args":"'..args..'", "cookie":"'..cookies..'", "agent":"'..useragent..'", "remote":"'..remote..'", "nowtime":"'..nowtime..'"}'
--ngx.say(line)
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("172.22.1.44", 2000)
if not ok then
ngx.say("failed to connect: ", err)
return
end
local res, err = red:auth("SEC")
red:hmset("proxy."..host, "http://"..host..reqUri, line)
red:close()
end
local ret,err = pcall(logall)
if ret then
return
else
ngx.say("failed ", err)
end
}
proxy_pass http://$http_host$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}