Mercurial > hg > nginx
comparison src/stream/ngx_stream_proxy_module.c @ 6786:906ac20234ed
Upstream: do not unnecessarily create per-request upstreams.
If proxy_pass (and friends) with variables evaluates an upstream
specified with literal address, nginx always created a per-request
upstream.
Now, if there's a matching upstream specified in the configuration
(either implicit or explicit), it will be used instead.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 31 Oct 2016 18:33:36 +0300 |
parents | d1d0dd69a419 |
children | 54cf51c4f07a |
comparison
equal
deleted
inserted
replaced
6785:d1d0dd69a419 | 6786:906ac20234ed |
---|---|
431 u->ssl_name = u->resolved->host; | 431 u->ssl_name = u->resolved->host; |
432 #endif | 432 #endif |
433 | 433 |
434 host = &u->resolved->host; | 434 host = &u->resolved->host; |
435 | 435 |
436 umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); | |
437 | |
438 uscfp = umcf->upstreams.elts; | |
439 | |
440 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
441 | |
442 uscf = uscfp[i]; | |
443 | |
444 if (uscf->host.len == host->len | |
445 && ((uscf->port == 0 && u->resolved->no_port) | |
446 || uscf->port == u->resolved->port) | |
447 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) | |
448 { | |
449 goto found; | |
450 } | |
451 } | |
452 | |
436 if (u->resolved->sockaddr) { | 453 if (u->resolved->sockaddr) { |
437 | 454 |
438 if (u->resolved->port == 0 | 455 if (u->resolved->port == 0 |
439 && u->resolved->sockaddr->sa_family != AF_UNIX) | 456 && u->resolved->sockaddr->sa_family != AF_UNIX) |
440 { | 457 { |
452 } | 469 } |
453 | 470 |
454 ngx_stream_proxy_connect(s); | 471 ngx_stream_proxy_connect(s); |
455 | 472 |
456 return; | 473 return; |
457 } | |
458 | |
459 umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); | |
460 | |
461 uscfp = umcf->upstreams.elts; | |
462 | |
463 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
464 | |
465 uscf = uscfp[i]; | |
466 | |
467 if (uscf->host.len == host->len | |
468 && ((uscf->port == 0 && u->resolved->no_port) | |
469 || uscf->port == u->resolved->port) | |
470 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) | |
471 { | |
472 goto found; | |
473 } | |
474 } | 474 } |
475 | 475 |
476 if (u->resolved->port == 0) { | 476 if (u->resolved->port == 0) { |
477 ngx_log_error(NGX_LOG_ERR, c->log, 0, | 477 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
478 "no port in upstream \"%V\"", host); | 478 "no port in upstream \"%V\"", host); |