comparison src/stream/ngx_stream_proxy_module.c @ 6675:ab9b4fd8c5b7

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".
author Vladimir Homutov <vl@nginx.com>
date Fri, 02 Sep 2016 18:27:05 +0300
parents 38143d1abdec
children df3a7c029dec
comparison
equal deleted inserted replaced
6674:38143d1abdec 6675:ab9b4fd8c5b7
390 u->start_sec = ngx_time(); 390 u->start_sec = ngx_time();
391 391
392 c->write->handler = ngx_stream_proxy_downstream_handler; 392 c->write->handler = ngx_stream_proxy_downstream_handler;
393 c->read->handler = ngx_stream_proxy_downstream_handler; 393 c->read->handler = ngx_stream_proxy_downstream_handler;
394 394
395 s->upstream_states = ngx_array_create(c->pool, 1,
396 sizeof(ngx_stream_upstream_state_t));
397 if (s->upstream_states == NULL) {
398 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
399 return;
400 }
401
395 if (c->type == SOCK_STREAM) { 402 if (c->type == SOCK_STREAM) {
396 p = ngx_pnalloc(c->pool, pscf->buffer_size); 403 p = ngx_pnalloc(c->pool, pscf->buffer_size);
397 if (p == NULL) { 404 if (p == NULL) {
398 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); 405 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
399 return; 406 return;
675 682
676 c->log->action = "connecting to upstream"; 683 c->log->action = "connecting to upstream";
677 684
678 u = s->upstream; 685 u = s->upstream;
679 686
687 u->state = ngx_array_push(s->upstream_states);
688 if (u->state == NULL) {
689 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
690 return;
691 }
692
693 ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));
694
680 rc = ngx_event_connect_peer(&u->peer); 695 rc = ngx_event_connect_peer(&u->peer);
681 696
682 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); 697 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc);
683 698
684 if (rc == NGX_ERROR) { 699 if (rc == NGX_ERROR) {
685 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); 700 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
686 return; 701 return;
687 } 702 }
703
704 u->state->peer = u->peer.name;
688 705
689 if (rc == NGX_BUSY) { 706 if (rc == NGX_BUSY) {
690 ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); 707 ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams");
691 ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); 708 ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY);
692 return; 709 return;