1diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c
2index 777e180..e302f52 100644
3--- a/src/http/modules/ngx_http_upstream_hash_module.c
4+++ b/src/http/modules/ngx_http_upstream_hash_module.c
5@@ -9,6 +9,9 @@
6 #include <ngx_core.h>
7 #include <ngx_http.h>
8
9+#if (NGX_HTTP_UPSTREAM_CHECK)
10+#include "ngx_http_upstream_check_module.h"
11+#endif
12
13 typedef struct {
14     uint32_t                            hash;
15@@ -240,6 +243,14 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
16             goto next;
17         }
18
19+#if (NGX_HTTP_UPSTREAM_CHECK)
20+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
21+            "get hash peer, check_index: %ui",
22+             peer->check_index);
23+        if (ngx_http_upstream_check_peer_down(peer->check_index)) {
24+            goto next;
25+        }
26+#endif
27         if (peer->max_fails
28             && peer->fails >= peer->max_fails
29             && now - peer->checked <= peer->fail_timeout)
30@@ -506,6 +517,14 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
31                 continue;
32             }
33
34+#if (NGX_HTTP_UPSTREAM_CHECK)
35+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
36+            "get consistent_hash peer, check_index: %ui",
37+             peer->check_index);
38+        if (ngx_http_upstream_check_peer_down(peer->check_index)) {
39+            continue;
40+        }
41+#endif
42             if (peer->server.len != server->len
43                 || ngx_strncmp(peer->server.data, server->data, server->len)
44                    != 0)
45diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c
46index 148d73a..913e395 100644
47--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c
48+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c
49@@ -9,6 +9,9 @@
50 #include <ngx_core.h>
51 #include <ngx_http.h>
52
53+#if (NGX_HTTP_UPSTREAM_CHECK)
54+#include "ngx_http_upstream_check_module.h"
55+#endif
56
57 typedef struct {
58     /* the round robin data must be first */
59@@ -212,6 +215,15 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
60             goto next_try;
61         }
62
63+#if (NGX_HTTP_UPSTREAM_CHECK)
64+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
65+            "get ip_hash peer, check_index: %ui",
66+             peer->check_index);
67+        if (ngx_http_upstream_check_peer_down(peer->check_index)) {
68+            goto next_try;
69+        }
70+#endif
71+
72         if (peer->max_fails
73             && peer->fails >= peer->max_fails
74             && now - peer->checked <= peer->fail_timeout)
75diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c
76index dbef95d..bbabb68 100644
77--- a/src/http/modules/ngx_http_upstream_least_conn_module.c
78+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c
79@@ -9,6 +9,9 @@
80 #include <ngx_core.h>
81 #include <ngx_http.h>
82
83+#if (NGX_HTTP_UPSTREAM_CHECK)
84+#include "ngx_http_upstream_check_module.h"
85+#endif
86
87 typedef struct {
88     ngx_uint_t                        *conns;
89@@ -203,6 +206,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
90             continue;
91         }
92
93+#if (NGX_HTTP_UPSTREAM_CHECK)
94+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
95+                "get least_conn peer, check_index: %ui",
96+                peer->check_index);
97+
98+        if (ngx_http_upstream_check_peer_down(peer->check_index)) {
99+            continue;
100+        }
101+#endif
102+
103         if (peer->max_fails
104             && peer->fails >= peer->max_fails
105             && now - peer->checked <= peer->fail_timeout)
106@@ -256,6 +269,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
107                 continue;
108             }
109
110+#if (NGX_HTTP_UPSTREAM_CHECK)
111+            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
112+                    "get least_conn peer, check_index: %ui",
113+                    peer->check_index);
114+
115+            if (ngx_http_upstream_check_peer_down(peer->check_index)) {
116+                continue;
117+            }
118+#endif
119+
120             if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) {
121                 continue;
122             }
123diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
124index 37c835c..54aa44d 100644
125--- a/src/http/ngx_http_upstream_round_robin.c
126+++ b/src/http/ngx_http_upstream_round_robin.c
127@@ -9,6 +9,9 @@
128 #include <ngx_core.h>
129 #include <ngx_http.h>
130
131+#if (NGX_HTTP_UPSTREAM_CHECK)
132+#include "ngx_http_upstream_check_module.h"
133+#endif
134
135 static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer(
136     ngx_http_upstream_rr_peer_data_t *rrp);
137@@ -88,6 +91,14 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
138                 peer[n].fail_timeout = server[i].fail_timeout;
139                 peer[n].down = server[i].down;
140                 peer[n].server = server[i].name;
141+#if (NGX_HTTP_UPSTREAM_CHECK)
142+                if (!server[i].down) {
143+                    peers->peer[n].check_index =
144+                        ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
145+                } else {
146+                    peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
147+                }
148+#endif
149                 n++;
150             }
151         }
152@@ -144,6 +155,15 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
153                 peer[n].fail_timeout = server[i].fail_timeout;
154                 peer[n].down = server[i].down;
155                 peer[n].server = server[i].name;
156+#if (NGX_HTTP_UPSTREAM_CHECK)
157+                if (!server[i].down) {
158+                    backup->peer[n].check_index =
159+                        ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
160+                }
161+                else {
162+                    backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
163+                }
164+#endif
165                 n++;
166             }
167         }
168@@ -203,6 +223,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
169         peer[i].current_weight = 0;
170         peer[i].max_fails = 1;
171         peer[i].fail_timeout = 10;
172+#if (NGX_HTTP_UPSTREAM_CHECK)
173+        peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
174+#endif
175     }
176
177     us->peer.data = peers;
178@@ -312,7 +335,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
179         peer[0].current_weight = 0;
180         peer[0].max_fails = 1;
181         peer[0].fail_timeout = 10;
182-
183+#if (NGX_HTTP_UPSTREAM_CHECK)
184+        peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
185+#endif
186     } else {
187
188         for (i = 0; i < ur->naddrs; i++) {
189@@ -352,6 +377,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
190             peer[i].current_weight = 0;
191             peer[i].max_fails = 1;
192             peer[i].fail_timeout = 10;
193+#if (NGX_HTTP_UPSTREAM_CHECK)
194+            peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
195+#endif
196         }
197     }
198
199@@ -411,6 +439,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
200             goto failed;
201         }
202
203+#if (NGX_HTTP_UPSTREAM_CHECK)
204+        if (ngx_http_upstream_check_peer_down(peer->check_index)) {
205+            goto failed;
206+        }
207+#endif
208+
209     } else {
210
211         /* there are several peers */
212@@ -508,6 +542,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
213             continue;
214         }
215
216+#if (NGX_HTTP_UPSTREAM_CHECK)
217+        if (ngx_http_upstream_check_peer_down(peer->check_index)) {
218+            continue;
219+        }
220+#endif
221+
222         if (peer->max_fails
223             && peer->fails >= peer->max_fails
224             && now - peer->checked <= peer->fail_timeout)
225diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h
226index 9db82a6..6e19a65 100644
227--- a/src/http/ngx_http_upstream_round_robin.h
228+++ b/src/http/ngx_http_upstream_round_robin.h
229@@ -31,6 +31,10 @@ typedef struct {
230     ngx_uint_t                      max_fails;
231     time_t                          fail_timeout;
232
233+#if (NGX_HTTP_UPSTREAM_CHECK)
234+    ngx_uint_t                      check_index;
235+#endif
236+
237     ngx_uint_t                      down;          /* unsigned  down:1; */
238
239 #if (NGX_HTTP_SSL)
240