-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
240 lines (200 loc) · 6.87 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
error_log /dev/stdout debug;
# lua_ssl_verify_depth 2;
lua_ssl_trusted_certificate '/etc/ssl/certs/ca-bundle.crt';
# set search paths for pure Lua external libraries (';;' is the default path):
# lua_package_path '/foo/bar/?.lua;/blah/?.lua;;';
# # set search paths for Lua external libraries written in C (can also use ';;'):
# lua_package_cpath '/bar/baz/?.so;/blah/blah/?.so;;';
server {
listen 80;
location /lua_content {
default_type 'text/plain';
content_by_lua_block {
ngx.log(ngx.DEBUG, "I am logging something")
ngx.say("hello, world!")
}
}
location /decode_info {
content_by_lua_block {
local json = require "cjson"
ngx.req.read_body()
local args = ngx.req.get_post_args()
if not args or not args.info then
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
local client_ip = ngx.var.remote_addr
local user_agent = ngx.req.get_headers()['user-agent'] or ''
local info = ngx.decode_base64(args.info)
local response = {}
response.info = info
response.ip = client_ip
response.user_agent = user_agent
ngx.say(json.encode(response))
}
}
location /slack {
resolver 8.8.8.8;
default_type "application/json";
content_by_lua_block {
local json = require "cjson"
local http = require "resty.http"
ngx.req.read_body()
local data = ngx.req.get_body_data()
local json_table = json.decode(data)
local gitsync_hash = json_table.headers["gitsync-hash"]
local attachments = {
{
color = "#1d9bd1",
fields = {
{
title = "Airflow Dags updated",
value = "Cluster is updated with <https://github.com/hk01-digital/data-airflow-dags|latest dags>",
},
{
title = "Commit",
value = gitsync_hash
},
},
mrkdwn_in = {
"text"
},
}
}
setmetatable(attachments, json.array_mt)
local slack_message = json.encode({
channel = "#alert-data-deploy",
username = "Airflow Dags Git-Sync Deployer",
icon_emoji = ":airflow:",
attachments = attachments,
})
local httpc = http.new()
local res, err = httpc:request_uri("https://l.wezeroplus.com/slack-webhook-alert-data", {
method = "POST",
body = slack_message,
headers = {
["Content-Type"] = "application/json",
},
keepalive_timeout = 60000,
keepalive_pool = 10,
})
if not res then
ngx.say("failed to request:", err)
return
end
ngx.say(slack_message)
}
}
location /request_body {
client_max_body_size 50k;
client_body_buffer_size 50k;
content_by_lua_block {
local json = require "cjson"
ngx.req.read_body()
local data = ngx.req.get_body_data()
local json_table = json.decode(data)
ngx.log(ngx.DEBUG, data)
ngx.say(json_table.kiosk_id)
}
}
location /get_random_string {
content_by_lua_block {
local args, err = ngx.req.get_uri_args()
if err == "truncated" then
-- one can choose to ignore or reject the current request here
end
local salt = args.salt
ngx.log(ngx.DEBUG, "what is salt " .. salt)
if not salt then
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
local string = ngx.md5(ngx.time() .. salt)
ngx.say(string)
}
}
location = /test {
content_by_lua_block {
local args, err = ngx.req.get_uri_args()
if err == "truncated" then
-- one can choose to ignore or reject the current request here
end
for key, val in pairs(args) do
if type(val) == "table" then
ngx.say(key, ": ", table.concat(val, ", "))
else
ngx.say(key, ": ", val)
end
end
}
}
location /simpleinterface {
resolver 8.8.8.8;
content_by_lua_block {
local http = require "resty.http"
local httpc = http.new()
local res, err = httpc:request_uri("http://example.com/helloworld", {
method = "POST",
body = "a=1&b=2",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
},
keepalive_timeout = 60000,
keepalive_pool = 10
})
if not res then
ngx.say("failed to request: ", err)
return
end
ngx.status = res.status
for k, v in pairs(res.headers) do
--
end
ngx.say(res.body)
}
}
location /genericinterface {
resolver 8.8.8.8;
content_by_lua_block {
local http = require "resty.http"
local httpc = http.new()
httpc:set_timeout(500)
httpc:connect("https://www.google.com")
local res, err = httpc:request({
path = "/",
headers = {
["Host"] = "example.com",
}
})
if not res then
ngx.say("failed to request: ", err)
end
local reader = res.body_reader
repeat
local chunk, err = reader(8192)
if err then
ngx.log(ngx.ERR, err)
break
end
if chunk then
-- process
end
until not chunk
local ok, err = httpc:set_keepalive()
if not ok then
ngx.say("failed to set keepalive: ", err)
end
}
}
location /baidu {
resolver 8.8.8.8;
content_by_lua_block {
local http = require "resty.http"
local httpc = http.new()
local res, err = httpc:request_uri("http://www.baidu.com")
if res.status == ngx.HTTP_OK then
ngx.say(res.body)
else
ngx.exit(res.status)
end
}
}
}