-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.lua
More file actions
84 lines (65 loc) · 1.71 KB
/
content.lua
File metadata and controls
84 lines (65 loc) · 1.71 KB
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
-- 通过content lua获取请求的url,参数,来源地址等,先做access处理,然后根据url和参数做rewrite处理,再做upstream处理
--
local cnfcache
local log = ngx.log
local ERR = ngx.ERR
local cjson = require("cjson")
local var = require("workvar")
local function errlog(...)
log(ERR, "Contant lua:", ...)
end
-- 从共享内存中取数据
local function getFromCache(key)
local cache_ngx = ngx.shared.globle_cache
local value = cache_ngx:get(key)
return value
end
-- 获取url 参数 来源IP
local function getParameter()
end
-- access处理
local function accessHandler()
end
-- rewrite 处理
local function rewriteHandler()
end
-- upstream处理
local function upstreamHandler()
end
local function locationHandler(localtion)
if not localtion["pass"] then
return
end
if localtion["access"] then
end
if localtion["rewrite"] then
end
pass = localtion["pass"]
if pass == "root" then
ngx.say(localtion[pass].. localtion["url"])
return
end
if pass == "upstream" then
upstream = localtion[pass]
ngx.var.upaddr = "127.0.0.1:8080"
end
end
local function handler()
-- 根据servername获取url
local servername = ngx.var.host
local requri = ngx.var.request_uri
-- 精确url处理
-- 获取精确url的列表
-- accurate_url = getFromCache(servername .. "=")
local cnf = var.getGlobleCnf()
local accurate_url = cnf[servername]["="]
-- errlog(cjson.encode(accurate_url))
if accurate_url[requri] then
location = cnf[servername][requri]
locationHandler(localtion)
return
end
-- 匹配url处理
-- 正则url处理
end
handler()