Upstream: fixed "no port" detection in evaluated upstreams.

If an upstream with variables evaluated to address without a port,
then instead of a "no port in upstream" error an attempt was made
to connect() which failed with EADDRNOTAVAIL.
This commit is contained in:
Ruslan Ermilov 2015-11-21 10:44:07 +03:00
parent cb5306984b
commit 72b9a317d2
5 changed files with 22 additions and 10 deletions

View File

@ -773,10 +773,11 @@ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
} else { } else {
u->resolved->host = url.host; u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
} }
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
return NGX_OK; return NGX_OK;
} }

View File

@ -1015,10 +1015,11 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
} else { } else {
u->resolved->host = url.host; u->resolved->host = url.host;
u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
u->resolved->no_port = url.no_port;
} }
u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
u->resolved->no_port = url.no_port;
return NGX_OK; return NGX_OK;
} }

View File

@ -569,10 +569,11 @@ ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf)
} else { } else {
u->resolved->host = url.host; u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
} }
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
return NGX_OK; return NGX_OK;
} }

View File

@ -771,10 +771,11 @@ ngx_http_uwsgi_eval(ngx_http_request_t *r, ngx_http_uwsgi_loc_conf_t * uwcf)
} else { } else {
u->resolved->host = url.host; u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
} }
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
return NGX_OK; return NGX_OK;
} }

View File

@ -633,8 +633,18 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
u->ssl_name = u->resolved->host; u->ssl_name = u->resolved->host;
#endif #endif
host = &u->resolved->host;
if (u->resolved->sockaddr) { if (u->resolved->sockaddr) {
if (u->resolved->port == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"no port in upstream \"%V\"", host);
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
if (ngx_http_upstream_create_round_robin_peer(r, u->resolved) if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
!= NGX_OK) != NGX_OK)
{ {
@ -648,8 +658,6 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
return; return;
} }
host = &u->resolved->host;
umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
uscfp = umcf->upstreams.elts; uscfp = umcf->upstreams.elts;