-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
94 lines (77 loc) · 3.08 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
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
# define upstreams:
upstream tile38-leader {
server tile38-leader:9851;
}
upstream tile38-follower {
server tile38-follower:9852;
}
# the size depends on the number of servers in upstream {}:
lua_shared_dict healthcheck 1m;
lua_socket_log_errors off;
init_worker_by_lua_block {
local hc = require "resty.upstream.healthcheck"
local leader_ok, err = hc.spawn_checker{
shm = "healthcheck", -- defined by "lua_shared_dict"
upstream = "tile38-leader", -- defined by "upstream"
type = "http",
http_req = "GET /healthz HTTP/1.0\r\nHost: tile38-leader\r\n\r\n",
-- raw HTTP request for checking
interval = 2000, -- run the check cycle every 2 sec
timeout = 1000, -- 1 sec is the timeout for network operations
fall = 3, -- # of successive failures before turning a peer down
rise = 2, -- # of successive successes before turning a peer up
valid_statuses = {200}, -- a list valid HTTP status code
concurrency = 10, -- concurrency level for test requests
}
if not leader_ok then
ngx.log(ngx.ERR, "failed to spawn tile38 leader health checker: ", err)
return
end
-- Just call hc.spawn_checker() for more times here if you have
-- more upstream groups to monitor.
local follower_ok, err = hc.spawn_checker{
shm = "healthcheck", -- defined by "lua_shared_dict"
upstream = "tile38-follower", -- defined by "upstream"
type = "http",
http_req = "GET /status HTTP/1.0\r\nHost: tile38-follower\r\n\r\n",
-- raw HTTP request for checking
interval = 2000, -- run the check cycle every 2 sec
timeout = 1000, -- 1 sec is the timeout for network operations
fall = 3, -- # of successive failures before turning a peer down
rise = 2, -- # of successive successes before turning a peer up
valid_statuses = {200}, -- a list valid HTTP status code
concurrency = 10, -- concurrency level for test requests
}
if not follower_ok then
ngx.log(ngx.ERR, "failed to spawn tile38-follwer health checker: ", err)
return
end
}
server {
listen 8080;
# default page:
location / {
default_type text/html;
content_by_lua_block {
ngx.say("hello, world")
}
}
# status page for all the peers:
location = /status {
access_log off;
default_type text/plain;
content_by_lua_block {
local hc = require "resty.upstream.healthcheck"
ngx.say("Upstream healthcheck for geospatial services")
ngx.say("Nginx Worker PID: ", ngx.worker.pid())
ngx.print(hc.status_page())
}
}
}
}