-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.conf
More file actions
526 lines (422 loc) · 19.9 KB
/
common.conf
File metadata and controls
526 lines (422 loc) · 19.9 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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
daemon off;
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log debug;
pid /var/run/nginx4.pid;
events{
use epoll;
worker_connections 1024;
}
http{
resolver 8.8.8.8;
resolver_timeout 10s;
server_tokens off;
lua_package_path "/home/ivan/modules/lua-resty-redis/lib/?.lua;/home/ivan/modules/lua-resty-core/lib/?.lua;;";
proxy_cache_path /home/ivan/cache1 levels=1:2 keys_zone=cache:2000m inactive=1d max_size=30g;
proxy_cache cache;
lua_shared_dict data 1000m;
gzip on;
# gzip_static on;
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 1024;
server {
listen 8002;
location / {
empty_gif;
}
}
server {
# this server shows keys and values from shared dict
server_name api;
listen 8080;
location / {
rewrite_by_lua_block{
local data = ngx.shared.data
ngx.say("data : ")
for _,v in pairs(ngx.shared.data:get_keys()) do
ngx.say(v.." : "..ngx.shared.data:get(v))
end
}
location /clear/ {
rewrite_by_lua_block{
ngx.shared.data:flush_all()
}
}
}
}
server{
# this block parse JSON file and add data to shared dict
server_name api;
listen 8085;
location /{
lua_need_request_body on;
rewrite_by_lua_file /home/ivan/nginx_configs/lua_configs/parse_json_from_request.lua;
}
}
server{
# this block parse JSON file and add data to shared dict
server_name api3;
listen 8086;
location /{
rewrite_by_lua_file /home/ivan/nginx_configs/lua_configs/parse_all_files.lua;
}
}
server {
# this block add and change data in shared dict from headers
server_name api2;
listen 8081;
location = /headers/add/ {
rewrite_by_lua_block{
local h = ngx.req.get_headers()
ngx.say(h['prefix'])
for k, v in pairs(h) do
ngx.say(k..' : '..v)
success, err, forcible = ngx.shared.data:set(k, v)
end
if success then
ngx.say("good")
else
ngx.say("bad")
end
}
}
}
server{
# server for customs use lua file
server_name custom2;
listen 8089;
set $cdn_client 01636_sberbank:01636_sberbank_1;
set $cdn_mp4store_status "-";
set $cdnvideo_rtlog_flag 0;
set $us "_";
set $cdn_traffic "E";
set $cdn_proxy_cache_key '';
set $cdn_proxy_pass '';
set $cdn_proxy_cache '';
set $acpt_enc '';
set $colon '';
set $cdn_proxy_temp_path '';
set $cdn_proxy_hide_header '';
resolver 8.8.8.8;
resolver_timeout 10s;
recursive_error_pages on;
set $args_req $args;
location / {
header_filter_by_lua_file /home/ivan/nginx_configs/lua_configs/custom_header_block.lua;
access_by_lua_file /home/ivan/nginx_configs/lua_configs/custom_access_block.lua;
proxy_temp_path /tmp/;
proxy_cache $cdn_proxy_cache;
proxy_cache_lock on;
proxy_cache_lock_timeout 1h;
proxy_cache_min_uses 1;
proxy_cache_key $cdn_proxy_cache_key;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_valid 200 301 302 304 24h;
proxy_cache_valid 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 431 0s;
proxy_cache_valid 500 501 502 503 504 505 506 507 508 509 510 511 0s;
proxy_cache_valid any 1s;
proxy_ignore_client_abort on;
proxy_next_upstream error timeout http_502 http_504;
proxy_connect_timeout 5;
proxy_read_timeout 20;
proxy_send_timeout 20;
proxy_pass $cdn_proxy_pass;
}
}
# server{
# server_name api;
# listen 8082;
# lua_need_request_body on;
# location /json/add/{
# access_by_lua_block{
# local data = ngx.shared.data
# local cjson = require("cjson")
# ngx.req.read_body()
# local text = ngx.var.request_body
# local value = cjson.decode(text)
# for _,hashtable in pairs(value) do
# for key,value in pairs(hashtable) do
# success, err, forcible = ngx.shared.data:set(key, value)
# if not success then
# return ngx.exit(404)
# end
# end
# end
# return ngx.exit(200)
# }
# }
# }
# server{
# server_name custom;
# listen 8088;
# set $cdn_client 01636_sberbank:01636_sberbank_1;
# set $cdn_mp4store_status "-";
# set $cdnvideo_rtlog_flag 0;
# set $us "_";
# set $cdn_traffic "E";
# resolver 8.8.8.8;
# resolver_timeout 10s;
# recursive_error_pages on;
# set $args_req $args;
# location / {
# proxy_temp_path /home/ivan/tmp;
# proxy_cache cache;
# proxy_cache_lock on;
# proxy_cache_lock_timeout 1h;
# proxy_cache_min_uses 1;
# set $acpt_enc "";
# set $colon "";
# header_filter_by_lua_block{
# local data = ngx.shared.data
# local prefix = ngx.req.get_headers()['prefix']
# local headers = {'X-Forwarded-For', 'X-Real-IP', 'Accept-Encoding', 'Host'}
# for i, header_name in pairs(headers) do
# ngx.header[prefix..header_name] = data:get(prefix..header_name)
# end
# }
# access_by_lua_block{
# local data = ngx.shared.data
# local my_data = {
# 'proxy_cache_key', 'proxy_pass', 'proxy_hide_header', 'proxy_cache', 'proxy_temp_path', 'expired_time'}
# # if ngx.var.uri == '/customs/sberbank/' then
# local prefix = ngx.req.get_headers()['prefix']
# for i, name in ipairs(my_data) do
# local temp = data:get(prefix..name)
# if temp == nil then
# if empty_data ~= nil then
# table.insert(empty_data, prefix..name)
# else
# empty_data = {}
# table.insert(empty_data, prefix..name)
# end
# end
# end
# if empty_data ~= nil then
# local filename = ngx.req.get_headers()['filename']
# local f = io.open(filename, "rb")
# if not f then
# f:close()
# ngx.header["Erorr"] = "JSON FILE NOT FOUND"
# return ngx.exit(404)
# else
# local content = f:read("all")
# f:close()
# local cjson = require("cjson")
# local value = cjson.decode(content)
# for _,hashtable in pairs(value) do
# for key,value in pairs(hashtable) do
# success, err, forcible = ngx.shared.data:set(key, value)
# data[key] = value
# if not success then
# ngx.header["Erorr"] = "JSON FILE "..filename.."Cannot decode"
# return ngx.exit(404)
# end
# end
# end
# end
# end
# exstentions = {
# "jpg", "jpeg", "gif", "png", "bmp",
# "tif", "tiff", "zip", "gz" ,"bz2",
# "flv", "mp3", "mp4", "m4v", "m4a", "ts"
# }
# if ngx.var.http_accept_encoding then
# if string.find(ngx.var.http_accept_encoding, "gzip") then
# ngx.var.acpt_enc = "gzip"
# ngx.var.colon = ""
# end
# else
# _, uri_exstension = ngx.var.uri:match("([^,]+),([^,]+)")
# for i, val in pairs(exstentions) do
# if val == uri_exstension then
# ngx.var.acpt_enc = ""
# ngx.var.colon = ""
# break
# end
# end
# end
# ngx.var.proxy_cache_key = data:get('sbr_proxy_cache_key')
# ngx.var.proxy_pass = data:get('sbr_proxy_pass')
# ngx.var.proxy_hide_header = data:get('sbr_proxy_hide_header')
# ngx.var.proxy_cache = data:get('sbr_proxy_cache')
# ngx.var.proxy_temp_path = data:get('sbr_proxy_temp_path')
# }
# if ($http_accept_encoding ~* gzip)
# {
# set $acpt_enc "gzip";
# set $colon ":";
# }
# if ($uri ~* '\.(jpg|jpeg|gif|png|bmp|tif|tiff|zip|gz|bz2|flv|mp3|mp4|m4v|m4a|ts)$')
# {
# set $acpt_enc "";
# set $colon "";
# }
# proxy_cache_key http://www.sberbank.ru$uri$colon$acpt_enc;
# proxy_set_header Accept-Encoding $acpt_enc;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_valid 200 301 302 304 24h;
# proxy_cache_valid 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 431 0s;
# proxy_cache_valid 500 501 502 503 504 505 506 507 508 509 510 511 0s;
# proxy_cache_valid any 1s;
# proxy_ignore_client_abort on;
# proxy_next_upstream error timeout http_502 http_504;
# proxy_connect_timeout 5;
# proxy_read_timeout 20;
# proxy_send_timeout 20;
# proxy_hide_header X-CDN-Cache-Status;
# proxy_set_header X-Forwarded-For "$proxy_add_x_forwarded_for";
# proxy_set_header X-Real-IP "$remote_addr";
# # working resolver requires variables in proxy_pass destination
# set $proxy_pass_to http://01636_sberbank_1;
# proxy_set_header Host 01636_sberbank_1;
# proxy_pass $proxy_pass_to;
# }
# }
# server{
# server_name _;
# listen 8080;
# location /{
# access_by_lua_block{
# local data = ngx.shared.data
# local my_data = {
# 'proxy_cache_key', 'proxy_pass', 'proxy_hide_header', 'proxy_cache', 'X-Forwarded-For','X-Real-IP', 'Accept-Encoding', 'Host', 'expired_time', 'proxy_temp_path'
# }
# if ngx.var.uri == '/sberbank/' then
# local prefix = 'sbr_'
# for i, name in ipairs(my_data) do
# if data:get(prefix..name) == nil then
# if empty_data ~= nil then
# table.insert(empty_data, prefix..name)
# else
# empty_data = {}
# table.insert(empty_data, prefix..name)
# end
# end
# end
# if empty_data ~= nil then
# data:set('sbr_proxy_cache_key', 'http://127.0.0.1:8085/showheaders/')
# data:set('sbr_proxy_pass', 'http://127.0.0.1:8082/images/1.jpg')
# data:set('sbr_proxy_hide_header', 'X-CDN-Cache-Status')
# data:set('sbr_proxy_cache', 'sberbank')
# data:set('sbr_X-Forwarded-For', 'sbr')
# data:set('sbr_X-Real-IP', 'sbr')
# data:set('sbr_Accept-Encoding', 'sbr')
# data:set('sbr_Host', 'sbr')
# data:set('sbr_expired_time', '200')
# data:set('sbr_proxy_temp_path', '/path/to/cache/')
# ngx.shared.data:set(data['sbr_proxy_cache_key'], 'http://127.0.0.1:8085/showheaders/', 200)
# ngx.shared.data:set(data['sbr_proxy_pass'], 'http://127.0.0.1:8082/images/1.jpg', 200)
# ngx.shared.data:set(data['sbr_proxy_hide_header'], 'X-CDN-Cache-Status', 200)
# ngx.shared.data:set(data['sbr_proxy_cache'], 'sberbank', 200)
# ngx.shared.data:set(data['sbr_X-Forwarded-For'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_X-Real-IP'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_Accept-Encoding'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_Host'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_expired_time'], 200)
# ngx.shared.data:set(data['sbr_proxy_temp_path'], '/path/to/cache/', 200)
# end
# ngx.exec("@sberbank")
# end
# }
# }
# location @sberbank{
# set $proxy_cache_key '';
# set $proxy_pass '';
# set $proxy_cache '';
# set $acpt_enc '';
# set $colon '';
# set $proxy_temp_path '';
# set $proxy_hide_header '';
# header_filter_by_lua_block{
# local data = ngx.shared.data
# local headers = {'sbr_X-Forwarded-For', 'sbr_X-Real-IP', 'sbr_Accept-Encoding', 'sbr_Host'}
# for i, header_name in pairs(headers) do
# ngx.log(ngx.INFO, "Setting: "..tostring(header_name).." ".. tostring(data:get(header_name)))
# ngx.header[header_name] = data:get(header_name)
# end
# }
# rewrite_by_lua_block{
# local data = ngx.shared.data
# local my_data = {
# 'sbr_proxy_cache_key', 'sbr_proxy_pass', 'sbr_proxy_hide_header', 'sbr_proxy_cache', 'sbr_expired_time', 'sbr_proxy_temp_path'
# }
# exstentions = {
# "jpg", "jpeg", "gif", "png", "bmp",
# "tif", "tiff", "zip", "gz" ,"bz2",
# "flv", "mp3", "mp4", "m4v", "m4a", "ts"
# }
# expired_time = 200
# for i, name in ipairs(my_data) do
# if data:get(name) == nil then
# if empty_data ~= nil then
# table.insert(empty_data, name)
# else
# empty_data = {}
# table.insert(empty_data, name)
# end
# end
# end
# if empty_data ~= nil then
# data:set('sbr_proxy_cache_key', 'http://127.0.0.1:8085/showheaders/')
# data:set('sbr_proxy_pass', 'http://127.0.0.1:8082/images/1.jpg')
# data:set('sbr_proxy_hide_header', 'X-CDN-Cache-Status')
# data:set('sbr_proxy_cache', 'sberbank')
# data:set('sbr_X-Forwarded-For', 'sbr')
# data:set('sbr_X-Real-IP', 'sbr')
# data:set('sbr_Accept-Encoding', 'sbr')
# data:set('sbr_Host', 'sbr')
# data:set('sbr_expired_time', '200')
# data:set('sbr_proxy_temp_path', '/path/to/cache/')
# ngx.shared.data:set(data['sbr_proxy_cache_key'], 'http://127.0.0.1:8085/showheaders/', 200)
# ngx.shared.data:set(data['sbr_proxy_pass'], 'http://127.0.0.1:8082/images/1.jpg', 200)
# ngx.shared.data:set(data['sbr_proxy_hide_header'], 'X-CDN-Cache-Status', 200)
# ngx.shared.data:set(data['sbr_proxy_cache'], 'sberbank', 200)
# ngx.shared.data:set(data['sbr_X-Forwarded-For'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_X-Real-IP'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_Accept-Encoding'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_Host'], 'sbr', 200)
# ngx.shared.data:set(data['sbr_expired_time'], 200)
# ngx.shared.data:set(data['sbr_proxy_temp_path'], '/path/to/cache/', 200)
# end
# ngx.var.proxy_cache_key = data:get('sbr_proxy_cache_key')
# ngx.var.proxy_pass = data:get('sbr_proxy_pass')
# ngx.var.proxy_hide_header = data:get('sbr_proxy_hide_header')
# ngx.var.proxy_cache = data:get('sbr_proxy_cache')
# ngx.var.proxy_temp_path = data:get('sbr_proxy_temp_path')
# if ngx.var.http_accept_encoding then
# if string.find(ngx.var.http_accept_encoding, "gzip") then
# ngx.var.acpt_enc = "gzip"
# ngx.var.colon = ""
# end
# else
# for i, val in pairs(exstentions) do
# if string.match(ngx.var.uri, val) then
# ngx.var.acpt_enc = ""
# ngx.var.colon = ""
# break
# end
# end
# end
# }
# proxy_temp_path $proxy_temp_path;
# proxy_cache $proxy_cache;
# proxy_cache_lock on;
# proxy_cache_lock_timeout 1h;
# proxy_cache_min_uses 1;
# proxy_cache_key $proxy_cache_key$uri$colon$acpt_enc;
# proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# proxy_cache_valid 200 301 302 304 2m;
# proxy_cache_valid 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 2m;
# proxy_cache_valid 500 501 502 503 504 505 506 507 508 509 510 511 2m;
# proxy_cache_valid any 2m;
# proxy_ignore_client_abort on;
# proxy_next_upstream error timeout http_502 http_504;
# proxy_connect_timeout 5s;
# proxy_read_timeout 5s;
# proxy_send_timeout 5s;
# proxy_hide_header $proxy_hide_header;
# proxy_pass $proxy_pass;
# }
# }
}