From c6d456da87fab9fc953f4f0d8506ac83415e774c Mon Sep 17 00:00:00 2001 From: Vladimir Homutov Date: Fri, 2 Sep 2016 18:27:05 +0300 Subject: Stream: the $upstream_addr variable. Keeps the full address of the upstream server. If several servers were contacted during proxying, their addresses are separated by commas, e.g. "192.168.1.1:80, 192.168.1.2:80". --- src/stream/ngx_stream_proxy_module.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/stream/ngx_stream_proxy_module.c') diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c index bf38ef7f8..dd8d7811d 100644 --- a/src/stream/ngx_stream_proxy_module.c +++ b/src/stream/ngx_stream_proxy_module.c @@ -392,6 +392,13 @@ ngx_stream_proxy_handler(ngx_stream_session_t *s) c->write->handler = ngx_stream_proxy_downstream_handler; c->read->handler = ngx_stream_proxy_downstream_handler; + s->upstream_states = ngx_array_create(c->pool, 1, + sizeof(ngx_stream_upstream_state_t)); + if (s->upstream_states == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + if (c->type == SOCK_STREAM) { p = ngx_pnalloc(c->pool, pscf->buffer_size); if (p == NULL) { @@ -677,6 +684,14 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s) u = s->upstream; + 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)); + rc = ngx_event_connect_peer(&u->peer); ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); @@ -686,6 +701,8 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s) return; } + u->state->peer = u->peer.name; + if (rc == NGX_BUSY) { ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); -- cgit v1.2.3