diff options
author | Ruslan Ermilov <ru@nginx.com> | 2016-10-31 18:33:36 +0300 |
---|---|---|
committer | Ruslan Ermilov <ru@nginx.com> | 2016-10-31 18:33:36 +0300 |
commit | 149fda55f730c38fb9e2c5b63370da92c0ad7c22 (patch) | |
tree | 433a6cde96c4b203af56fbb9930c857a978e3ece /src/stream/ngx_stream_proxy_module.c | |
parent | 3fae83a91c6e5cda012adf6ee2783273e747f613 (diff) | |
download | nginx-149fda55f730c38fb9e2c5b63370da92c0ad7c22.tar.gz nginx-149fda55f730c38fb9e2c5b63370da92c0ad7c22.zip |
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.
Diffstat (limited to 'src/stream/ngx_stream_proxy_module.c')
-rw-r--r-- | src/stream/ngx_stream_proxy_module.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c index 4af907c23..c03b51505 100644 --- a/src/stream/ngx_stream_proxy_module.c +++ b/src/stream/ngx_stream_proxy_module.c @@ -433,6 +433,23 @@ ngx_stream_proxy_handler(ngx_stream_session_t *s) host = &u->resolved->host; + umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); + + uscfp = umcf->upstreams.elts; + + for (i = 0; i < umcf->upstreams.nelts; i++) { + + uscf = uscfp[i]; + + if (uscf->host.len == host->len + && ((uscf->port == 0 && u->resolved->no_port) + || uscf->port == u->resolved->port) + && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) + { + goto found; + } + } + if (u->resolved->sockaddr) { if (u->resolved->port == 0 @@ -456,23 +473,6 @@ ngx_stream_proxy_handler(ngx_stream_session_t *s) return; } - umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); - - uscfp = umcf->upstreams.elts; - - for (i = 0; i < umcf->upstreams.nelts; i++) { - - uscf = uscfp[i]; - - if (uscf->host.len == host->len - && ((uscf->port == 0 && u->resolved->no_port) - || uscf->port == u->resolved->port) - && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) - { - goto found; - } - } - if (u->resolved->port == 0) { ngx_log_error(NGX_LOG_ERR, c->log, 0, "no port in upstream \"%V\"", host); |