aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_proxy_module.c
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2016-09-02 18:27:05 +0300
committerVladimir Homutov <vl@nginx.com>2016-09-02 18:27:05 +0300
commitc6d456da87fab9fc953f4f0d8506ac83415e774c (patch)
treecbd9d030a98665e799502539bde8a9478858eb0a /src/stream/ngx_stream_proxy_module.c
parentbe6024f9b72b6d012d52f1ae1c7605a6c4c165da (diff)
downloadnginx-c6d456da87fab9fc953f4f0d8506ac83415e774c.tar.gz
nginx-c6d456da87fab9fc953f4f0d8506ac83415e774c.zip
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".
Diffstat (limited to 'src/stream/ngx_stream_proxy_module.c')
-rw-r--r--src/stream/ngx_stream_proxy_module.c17
1 files changed, 17 insertions, 0 deletions
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);