Skip to content

Commit 3dc5902

Browse files
committed
merge from development branch
1 parent 669f88d commit 3dc5902

20 files changed

+5609
-659
lines changed

README

+108-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Name
2-
nginx_http_upstream_check_module - support health check with Nginx
2+
nginx_http_upstream_check_module - support upstream health check with
3+
Nginx
34

45
Synopsis
56
http {
@@ -10,12 +11,12 @@ Synopsis
1011
server 192.168.0.1:80;
1112
server 192.168.0.2:80;
1213

13-
check interval=3000 rise=2 fall=5 timeout=1000;
14+
check interval=5000 rise=1 fall=3 timeout=4000;
1415

1516
#check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;
1617

1718
#check interval=3000 rise=2 fall=5 timeout=1000 type=http;
18-
#check_http_send "GET / HTTP/1.0\r\n\r\n";
19+
#check_http_send "HEAD / HTTP/1.0\r\n\r\n";
1920
#check_http_expect_alive http_2xx http_3xx;
2021
}
2122

@@ -44,7 +45,7 @@ Directives
4445
check
4546
syntax: *check interval=milliseconds [fall=count] [rise=count]
4647
[timeout=milliseconds] [default_down=true|false]
47-
[type=tcp|http|ssl_hello|mysql|ajp]*
48+
[type=tcp|http|ssl_hello|mysql|ajp|fastcgi]*
4849

4950
default: *none, if parameters omitted, default parameters are
5051
interval=30000 fall=5 rise=2 timeout=1000 default_down=true type=tcp*
@@ -68,6 +69,10 @@ Directives
6869
* *default_down*: set initial state of backend server, default is
6970
down.
7071

72+
* `port`: specify the check port in the backend servers. It can be
73+
different with the original servers port. Default the port is 0 and
74+
it means the same as the original backend server.
75+
7176
* *type*: the check protocol type:
7277

7378
1. *tcp* is a simple tcp socket connect and peek one byte.
@@ -84,6 +89,9 @@ Directives
8489
5. *ajp* sends a AJP Cping packet, receives and parses the AJP
8590
Cpong response to diagnose if the upstream server is alive.
8691

92+
6. *fastcgi* send a fastcgi request, receives and parses the
93+
fastcgi response to diagnose if the upstream server is alive.
94+
8795
check_http_send
8896
syntax: *check_http_send http_packet*
8997

@@ -105,10 +113,36 @@ Directives
105113
description: These status codes indicate the upstream server's http
106114
response is ok, the backend is alive.
107115

116+
check_keepalive_requests
117+
syntax: *check_keepalive_requests num*
118+
119+
default: *check_keepalive_requests 1*
120+
121+
context: *upstream*
122+
123+
description: The directive specifies the number of requests sent on a
124+
connection, the default vaule 1 indicates that nginx will certainly
125+
close the connection after a request.
126+
127+
check_fastcgi_param
128+
Syntax: *check_fastcgi_params parameter value*
129+
130+
default: see below
131+
132+
context: *upstream*
133+
134+
description: If you set the check type is fastcgi, then the check
135+
function will sends this fastcgi headers to check the upstream server.
136+
The default directive looks like:
137+
138+
check_fastcgi_param "REQUEST_METHOD" "GET";
139+
check_fastcgi_param "REQUEST_URI" "/";
140+
check_fastcgi_param "SCRIPT_FILENAME" "index.php";
141+
108142
check_shm_size
109143
syntax: *check_shm_size size*
110144

111-
default: *1m*
145+
default: *1M*
112146

113147
context: *http*
114148

@@ -117,7 +151,7 @@ Directives
117151
enlarge it with this directive.
118152

119153
check_status
120-
syntax: *check_status*
154+
syntax: *check_status [html|csv|json]*
121155

122156
default: *none*
123157

@@ -126,6 +160,60 @@ Directives
126160
description: Display the health checking servers' status by HTTP. This
127161
directive should be set in the http block.
128162

163+
You can specify the default display format. The formats can be `html`,
164+
`csv` or `json`. The default type is `html`. It also supports to specify
165+
the format by the request argument. Suppose your `check_status` location
166+
is '/status', the argument of `format` can change the display page's
167+
format. You can do like this:
168+
169+
/status?format=html
170+
/status?format=csv
171+
/status?format=json
172+
173+
At present, you can fetch the list of servers with the same status by
174+
the argument of `status`. For example:
175+
176+
/status?format=html&status=down
177+
/status?format=csv&status=up
178+
179+
Below it's the sample html page:
180+
181+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN
182+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
183+
<title>Nginx http upstream check status</title>
184+
<h1>Nginx http upstream check status</h1>
185+
<h2>Check upstream server number: 1, generation: 3</h2>
186+
<th>Index</th>
187+
<th>Upstream</th>
188+
<th>Name</th>
189+
<th>Status</th>
190+
<th>Rise counts</th>
191+
<th>Fall counts</th>
192+
<th>Check type</th>
193+
<th>Check port</th>
194+
<td>0</td>
195+
<td>backend</td>
196+
<td>106.187.48.116:80</td>
197+
<td>up</td>
198+
<td>39</td>
199+
<td>0</td>
200+
<td>http</td>
201+
<td>80</td>
202+
203+
Below it's the sample of csv page:
204+
205+
0,backend,106.187.48.116:80,up,46,0,http,80
206+
207+
Below it's the sample of json page:
208+
209+
{"servers": {
210+
"total": 1,
211+
"generation": 3,
212+
"server": [
213+
{"index": 0, "upstream": "backend", "name": "106.187.48.116:80", "status": "up", "rise": 58, "fall": 0, "type": "http", "port": 80}
214+
]
215+
}}
216+
129217
Installation
130218
Download the latest version of the release tarball of this module from
131219
github (<http://github.com/yaoweibin/nginx_upstream_check_module>)
@@ -155,6 +243,12 @@ Note
155243
If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin
156244
module. You should use the patch named 'check_1.2.6+.patch'.
157245

246+
If you use nginx-1.5.12+, You should use the patch named
247+
'check_1.5.12+.patch'.
248+
249+
If you use nginx-1.7.2+, You should use the patch named
250+
'check_1.7.2+.patch'.
251+
158252
The patch just adds the support for the official Round-Robin, Ip_hash
159253
and least_conn upstream module. But it's easy to expand my module to
160254
other upstream modules. See the patch for detail.
@@ -209,9 +303,15 @@ Copyright & License
209303

210304
This module is licensed under the BSD license.
211305

212-
Copyright (C) 2012 by Weibin Yao <[email protected]>.
306+
Copyright (C) 2014 by Weibin Yao <[email protected]>
307+
308+
Copyright (C) 2010-2014 Alibaba Group Holding Limited
309+
310+
Copyright (C) 2014 by LiangBin Li
311+
312+
Copyright (C) 2014 by Zhuo Yuan
213313

214-
Copyright (C) 2012 by Matthieu Tourne.
314+
Copyright (C) 2012 by Matthieu Tourne
215315

216316
All rights reserved.
217317

check.patch

+23-23
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ index fd9ecbe..d3849b6 100644
66
#include <ngx_core.h>
77
#include <ngx_http.h>
88

9-
+#if (NGX_UPSTREAM_CHECK_MODULE)
10-
+#include "ngx_http_upstream_check_handler.h"
9+
+#if (NGX_HTTP_UPSTREAM_CHECK)
10+
+#include "ngx_http_upstream_check_module.h"
1111
+#endif
1212
+
1313

@@ -17,11 +17,11 @@ index fd9ecbe..d3849b6 100644
1717

1818
if (!peer->down) {
1919

20-
+#if (NGX_UPSTREAM_CHECK_MODULE)
20+
+#if (NGX_HTTP_UPSTREAM_CHECK)
2121
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
2222
+ "get ip_hash peer, check_index: %ui",
2323
+ peer->check_index);
24-
+ if (!ngx_http_check_peer_down(peer->check_index)) {
24+
+ if (!ngx_http_upstream_check_peer_down(peer->check_index)) {
2525
+#endif
2626
if (peer->max_fails == 0 || peer->fails < peer->max_fails) {
2727
break;
@@ -30,7 +30,7 @@ index fd9ecbe..d3849b6 100644
3030
peer->fails = 0;
3131
break;
3232
}
33-
+#if (NGX_UPSTREAM_CHECK_MODULE)
33+
+#if (NGX_HTTP_UPSTREAM_CHECK)
3434
+ }
3535
+#endif
3636
}
@@ -44,8 +44,8 @@ index afc9b2e..1c0344e 100644
4444
#include <ngx_core.h>
4545
#include <ngx_http.h>
4646

47-
+#if (NGX_UPSTREAM_CHECK_MODULE)
48-
+#include "ngx_http_upstream_check_handler.h"
47+
+#if (NGX_HTTP_UPSTREAM_CHECK)
48+
+#include "ngx_http_upstream_check_module.h"
4949
+#endif
5050

5151
static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
@@ -55,10 +55,10 @@ index afc9b2e..1c0344e 100644
5555
peers->peer[n].weight = server[i].down ? 0 : server[i].weight;
5656
peers->peer[n].current_weight = peers->peer[n].weight;
5757
+
58-
+#if (NGX_UPSTREAM_CHECK_MODULE)
58+
+#if (NGX_HTTP_UPSTREAM_CHECK)
5959
+ if (!server[i].down) {
6060
+ peers->peer[n].check_index =
61-
+ ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
61+
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
6262
+ }
6363
+ else {
6464
+ peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
@@ -73,10 +73,10 @@ index afc9b2e..1c0344e 100644
7373
backup->peer[n].fail_timeout = server[i].fail_timeout;
7474
backup->peer[n].down = server[i].down;
7575
+
76-
+#if (NGX_UPSTREAM_CHECK_MODULE)
76+
+#if (NGX_HTTP_UPSTREAM_CHECK)
7777
+ if (!server[i].down) {
7878
+ backup->peer[n].check_index =
79-
+ ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
79+
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
8080
+ }
8181
+ else {
8282
+ backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
@@ -90,7 +90,7 @@ index afc9b2e..1c0344e 100644
9090
peers->peer[i].current_weight = 1;
9191
peers->peer[i].max_fails = 1;
9292
peers->peer[i].fail_timeout = 10;
93-
+#if (NGX_UPSTREAM_CHECK_MODULE)
93+
+#if (NGX_HTTP_UPSTREAM_CHECK)
9494
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
9595
+#endif
9696
}
@@ -100,7 +100,7 @@ index afc9b2e..1c0344e 100644
100100
peers->peer[0].current_weight = 1;
101101
peers->peer[0].max_fails = 1;
102102
peers->peer[0].fail_timeout = 10;
103-
+#if (NGX_UPSTREAM_CHECK_MODULE)
103+
+#if (NGX_HTTP_UPSTREAM_CHECK)
104104
+ peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
105105
+#endif
106106

@@ -110,7 +110,7 @@ index afc9b2e..1c0344e 100644
110110
peers->peer[i].current_weight = 1;
111111
peers->peer[i].max_fails = 1;
112112
peers->peer[i].fail_timeout = 10;
113-
+#if (NGX_UPSTREAM_CHECK_MODULE)
113+
+#if (NGX_HTTP_UPSTREAM_CHECK)
114114
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
115115
+#endif
116116
}
@@ -121,8 +121,8 @@ index afc9b2e..1c0344e 100644
121121
if (rrp->peers->single) {
122122
peer = &rrp->peers->peer[0];
123123
-
124-
+#if (NGX_UPSTREAM_CHECK_MODULE)
125-
+ if (ngx_http_check_peer_down(peer->check_index)) {
124+
+#if (NGX_HTTP_UPSTREAM_CHECK)
125+
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
126126
+ return NGX_BUSY;
127127
+ }
128128
+#endif
@@ -133,11 +133,11 @@ index afc9b2e..1c0344e 100644
133133

134134
if (!peer->down) {
135135

136-
+#if (NGX_UPSTREAM_CHECK_MODULE)
136+
+#if (NGX_HTTP_UPSTREAM_CHECK)
137137
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
138138
+ "get rr peer, check_index: %ui",
139139
+ peer->check_index);
140-
+ if (!ngx_http_check_peer_down(peer->check_index)) {
140+
+ if (!ngx_http_upstream_check_peer_down(peer->check_index)) {
141141
+#endif
142142
if (peer->max_fails == 0
143143
|| peer->fails < peer->max_fails)
@@ -146,7 +146,7 @@ index afc9b2e..1c0344e 100644
146146
peer->fails = 0;
147147
break;
148148
}
149-
+#if (NGX_UPSTREAM_CHECK_MODULE)
149+
+#if (NGX_HTTP_UPSTREAM_CHECK)
150150
+ }
151151
+#endif
152152

@@ -156,11 +156,11 @@ index afc9b2e..1c0344e 100644
156156

157157
if (!peer->down) {
158158

159-
+#if (NGX_UPSTREAM_CHECK_MODULE)
159+
+#if (NGX_HTTP_UPSTREAM_CHECK)
160160
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
161161
+ "get rr peer2, check_index: %ui",
162162
+ peer->check_index);
163-
+ if (!ngx_http_check_peer_down(peer->check_index)) {
163+
+ if (!ngx_http_upstream_check_peer_down(peer->check_index)) {
164164
+#endif
165165
if (peer->max_fails == 0
166166
|| peer->fails < peer->max_fails)
@@ -169,7 +169,7 @@ index afc9b2e..1c0344e 100644
169169
peer->fails = 0;
170170
break;
171171
}
172-
+#if (NGX_UPSTREAM_CHECK_MODULE)
172+
+#if (NGX_HTTP_UPSTREAM_CHECK)
173173
+ }
174174
+#endif
175175

@@ -183,7 +183,7 @@ index 6d285ab..354cca2 100644
183183
ngx_uint_t max_fails;
184184
time_t fail_timeout;
185185

186-
+#if (NGX_UPSTREAM_CHECK_MODULE)
186+
+#if (NGX_HTTP_UPSTREAM_CHECK)
187187
+ ngx_uint_t check_index;
188188
+#endif
189189
+

0 commit comments

Comments
 (0)