Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ or
cp /path/to/module/nginx.1.10.1.patch /path/to/nginx-1.10.0/debian/patches (nginx 1.10 on debian)
or
patch -p1 < nginx-1.12.1.patch (nginx 1.12.X)
or
patch -p1 < nginx-1.28.0.patch (nginx 1.28.X)

if you want to use the module for stream, use this patch in addition:
patch -p1 < nginx-1.12.1-stream.patch
patch -p1 < nginx-1.12.1-stream.patch (nginx 1.21.1)
or
patch -p1 < nginx-1.28.0-stream.patch (nginx 1.28.X)

./configure --add-module=/path/to/module
make
Expand All @@ -122,6 +126,7 @@ However, I did not test it on the other versions :)
The nginx.1.4.4.patch is based on nginx 1.4.4, and tested only under nginx 1.4.4.
And there is patches for nginx.1.8.1 and 1.10.1.
Thanks to @ivan-antonyuck, who made patch for nginx 1.10.X and 1.10 on debian.
The nginx-1.28.0.patch is based on nginx 1.28.0, and tested only under nginx 1.28.0.

=BUGS==================================================================

Expand Down
114 changes: 114 additions & 0 deletions nginx-1.28.0-stream.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
index 6e51585f6..4f7c5570f 100644
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -66,7 +66,7 @@ static ngx_int_t ngx_stream_proxy_eval(ngx_stream_session_t *s,
ngx_stream_proxy_srv_conf_t *pscf);
static ngx_int_t ngx_stream_proxy_set_local(ngx_stream_session_t *s,
ngx_stream_upstream_t *u, ngx_stream_upstream_local_t *local);
-static void ngx_stream_proxy_connect(ngx_stream_session_t *s);
+void ngx_stream_proxy_connect(ngx_stream_session_t *s);
static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s);
static void ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx);
static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev);
@@ -80,7 +80,7 @@ static void ngx_stream_proxy_process(ngx_stream_session_t *s,
static ngx_int_t ngx_stream_proxy_test_finalize(ngx_stream_session_t *s,
ngx_uint_t from_upstream);
static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s);
-static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc);
+void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc);
static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf,
size_t len);

@@ -706,7 +706,7 @@ ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u,
}


-static void
+void
ngx_stream_proxy_connect(ngx_stream_session_t *s)
{
ngx_int_t rc;
@@ -722,31 +722,37 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s)

u = s->upstream;

- u->connected = 0;
- u->proxy_protocol = pscf->proxy_protocol;
+ if (!u->blocked) {
+ u->connected = 0;
+ u->proxy_protocol = pscf->proxy_protocol;

- if (u->state) {
- u->state->response_time = ngx_current_msec - u->start_time;
- }
+ if (u->state) {
+ u->state->response_time = ngx_current_msec - u->start_time;
+ }

- u->state = ngx_array_push(s->upstream_states);
- if (u->state == NULL) {
- ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
- return;
- }
+ u->state = ngx_array_push(s->upstream_states);
+ if (u->state == NULL) {
+ ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
+ return;
+ }

- ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));
+ ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));

- u->start_time = ngx_current_msec;
+ u->start_time = ngx_current_msec;

- u->state->connect_time = (ngx_msec_t) -1;
- u->state->first_byte_time = (ngx_msec_t) -1;
- u->state->response_time = (ngx_msec_t) -1;
+ u->state->connect_time = (ngx_msec_t) -1;
+ u->state->first_byte_time = (ngx_msec_t) -1;
+ u->state->response_time = (ngx_msec_t) -1;
+ }

rc = ngx_event_connect_peer(&u->peer);

ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc);

+ if (rc == NGX_BLOCK) {
+ return;
+ }
+
if (rc == NGX_ERROR) {
ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
return;
@@ -2015,7 +2021,7 @@ ngx_stream_proxy_test_finalize(ngx_stream_session_t *s,
}


-static void
+void
ngx_stream_proxy_next_upstream(ngx_stream_session_t *s)
{
ngx_msec_t timeout;
@@ -2081,7 +2087,7 @@ ngx_stream_proxy_next_upstream(ngx_stream_session_t *s)
}


-static void
+void
ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc)
{
ngx_uint_t state;
diff --git a/src/stream/ngx_stream_upstream.h b/src/stream/ngx_stream_upstream.h
index c581aa0be..7b375fe32 100644
--- a/src/stream/ngx_stream_upstream.h
+++ b/src/stream/ngx_stream_upstream.h
@@ -148,6 +148,7 @@ typedef struct {
unsigned connected:1;
unsigned proxy_protocol:1;
unsigned half_closed:1;
+ unsigned blocked:1;
} ngx_stream_upstream_t;


108 changes: 108 additions & 0 deletions nginx-1.28.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 02890b843..8b811cc9a 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -43,6 +43,7 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
#define NGX_DONE -4
#define NGX_DECLINED -5
#define NGX_ABORT -6
+#define NGX_BLOCK -7


#include <ngx_errno.h>
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index d4cf1b7fe..b0806e531 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -35,8 +35,6 @@ static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r);
static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r);
static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
ngx_event_t *ev);
-static void ngx_http_upstream_connect(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r,
ngx_http_upstream_t *u);
static void ngx_http_upstream_send_request(ngx_http_request_t *r,
@@ -1546,39 +1544,45 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
}


-static void
+void
ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;

- r->connection->log->action = "connecting to upstream";
+ if (!u->blocked) {
+ r->connection->log->action = "connecting to upstream";

- if (u->state && u->state->response_time == (ngx_msec_t) -1) {
- u->state->response_time = ngx_current_msec - u->start_time;
- }
+ if (u->state && u->state->response_time == (ngx_msec_t) -1) {
+ u->state->response_time = ngx_current_msec - u->start_time;
+ }

- u->state = ngx_array_push(r->upstream_states);
- if (u->state == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
+ u->state = ngx_array_push(r->upstream_states);
+ if (u->state == NULL) {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }

- ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
+ ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));

- u->start_time = ngx_current_msec;
+ u->start_time = ngx_current_msec;

- u->state->response_time = (ngx_msec_t) -1;
- u->state->connect_time = (ngx_msec_t) -1;
- u->state->header_time = (ngx_msec_t) -1;
+ u->state->response_time = (ngx_msec_t) -1;
+ u->state->connect_time = (ngx_msec_t) -1;
+ u->state->header_time = (ngx_msec_t) -1;
+ }

rc = ngx_event_connect_peer(&u->peer);

ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream connect: %i", rc);

+ if (rc == NGX_BLOCK) {
+ return;
+ }
+
if (rc == NGX_ERROR) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index e0a903669..7abc51f44 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -408,6 +408,7 @@ struct ngx_http_upstream_s {
unsigned request_body_sent:1;
unsigned request_body_blocked:1;
unsigned header_sent:1;
+ unsigned blocked:1;
};


@@ -441,6 +442,8 @@ ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
ngx_int_t ngx_http_upstream_merge_ssl_passwords(ngx_conf_t *cf,
ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev);
#endif
+void ngx_http_upstream_connect(ngx_http_request_t *r,
+ ngx_http_upstream_t *u);


#define ngx_http_conf_upstream_srv_conf(uscf, module) \