Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.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 | 563a1ee345a4 |
children | 640e1e778de6 |
comparison
equal
deleted
inserted
replaced
6785:d1d0dd69a419 | 6786:906ac20234ed |
---|---|
652 u->ssl_name = u->resolved->host; | 652 u->ssl_name = u->resolved->host; |
653 #endif | 653 #endif |
654 | 654 |
655 host = &u->resolved->host; | 655 host = &u->resolved->host; |
656 | 656 |
657 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
658 | |
659 uscfp = umcf->upstreams.elts; | |
660 | |
661 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
662 | |
663 uscf = uscfp[i]; | |
664 | |
665 if (uscf->host.len == host->len | |
666 && ((uscf->port == 0 && u->resolved->no_port) | |
667 || uscf->port == u->resolved->port) | |
668 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) | |
669 { | |
670 goto found; | |
671 } | |
672 } | |
673 | |
657 if (u->resolved->sockaddr) { | 674 if (u->resolved->sockaddr) { |
658 | 675 |
659 if (u->resolved->port == 0 | 676 if (u->resolved->port == 0 |
660 && u->resolved->sockaddr->sa_family != AF_UNIX) | 677 && u->resolved->sockaddr->sa_family != AF_UNIX) |
661 { | 678 { |
675 } | 692 } |
676 | 693 |
677 ngx_http_upstream_connect(r, u); | 694 ngx_http_upstream_connect(r, u); |
678 | 695 |
679 return; | 696 return; |
680 } | |
681 | |
682 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); | |
683 | |
684 uscfp = umcf->upstreams.elts; | |
685 | |
686 for (i = 0; i < umcf->upstreams.nelts; i++) { | |
687 | |
688 uscf = uscfp[i]; | |
689 | |
690 if (uscf->host.len == host->len | |
691 && ((uscf->port == 0 && u->resolved->no_port) | |
692 || uscf->port == u->resolved->port) | |
693 && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) | |
694 { | |
695 goto found; | |
696 } | |
697 } | 697 } |
698 | 698 |
699 if (u->resolved->port == 0) { | 699 if (u->resolved->port == 0) { |
700 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 700 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
701 "no port in upstream \"%V\"", host); | 701 "no port in upstream \"%V\"", host); |