-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.nginx.conf
115 lines (102 loc) · 2.86 KB
/
test.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
#### GLOBAL ####
user www www;
#pid logs/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
#### EVENT ####
events {
use epoll;
worker_connections 65535;
}
#### HTTP ####
http {
#include mime.types;
default_type text/plain;
index index.php index.html;
error_log /data1/ms/log/nginx/error.log info;
log_format combined2 '$remote_addr - $remote_user [$time_local] $upstream_response_time $request_time '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /data1/ms/log/nginx/access.log combined2;
sendfile on;
send_timeout 30; #If the client does not receive anything within this time, the connection is closed.
keepalive_timeout 30; #idle seconds
server_tokens off;
client_body_timeout 10;
client_header_timeout 10;
lua_package_path '/data1/ms/front/docker/config/openresty/?.lua;;';
lua_shared_dict fuse_shard_dict 10m;
#lua_code_cache off;
init_worker_by_lua_block {
local fuse = require "url_fuse"
local lib = require "lib"
fuse:setup(function(this)
this.LIFETIME = 15
this.FAILS_LIMIT = 2
this.REQUEST_TIMEOUT = 0.5
this.FUSED_DURATION = 5
this.DEBUG = true
this.ON_DEGRADED_CALLBACK = function(self)
ngx.header.x_degraded_end = this:get('fuse_end')
ngx.header.x_in_degraded = 1
ngx.status = 403
ngx.print(lib:json(fuse:counters()))
return ngx.exit(403)
end
this.BEFORE_HALF_OPEN_CALLBACK = function(self)
ngx.header.x_before_half_open = 1
end
this.AFTER_HALF_OPEN_CALLBACK = function(self)
ngx.header.x_degraded_end = this:get('fuse_end')
ngx.header.x_after_half_open = 1
print(lib:json(fuse:counters()))
end
this.VALIDATE_REQUEST = function(self)
local elapsed = ngx.now() - ngx.req.start_time()
if self.DEBUG then
self:debug("elapsed: ", elapsed)
end
local ret = elapsed < self.REQUEST_TIMEOUT
return ret
end
end)
}
server {
listen 80;
root /data1/ms/front/;
location ~ ^/.*(\.js|\.css|\.png|\.gif|\.jpg|favicon\.ico)$ {
log_not_found off;
access_log off;
}
location / {
access_by_lua_block {
local fuse = require "url_fuse"
print("debug ", fuse.DEBUG)
fuse:run_access()
}
log_by_lua_block {
local fuse = require "url_fuse"
fuse:run_log()
}
content_by_lua_block {
local fuse = require "url_fuse"
local lib = require "lib"
--mock fastcgi/uwsgi/...
local arg = ngx.req.get_uri_args()
local counters=fuse:counters()
for k,v in pairs(arg) do
--ngx.say("[GET ] key:", k, " v:", v)
counters['GET_'..k]=v
if k == 'sleep' then
ngx.sleep(v)
print('sleep done:', v)
end
end
counters['done']=1
counters['bucket_id']=fuse.bucket_id
ngx.print(lib:json(counters))
print(lib:json(counters))
}
}
}
}