mirror of
https://github.com/nginx/nginx.git
synced 2025-06-09 19:12:47 +08:00
Fixed "proxy_pass" with IP address and no port (ticket #276).
Upstreams created by "proxy_pass" with IP address and no port were broken in 1.3.10, by not initializing port in u->sockaddr. API change: ngx_parse_url() was modified to always initialize port (in u->sockaddr and in u->port), even for the u->no_resolve case; ngx_http_upstream() and ngx_http_upstream_add() were adopted.
This commit is contained in:
parent
2cbb7ae42a
commit
a2a229193a
@ -707,11 +707,8 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)
|
|||||||
}
|
}
|
||||||
|
|
||||||
u->no_port = 1;
|
u->no_port = 1;
|
||||||
|
u->port = u->default_port;
|
||||||
if (!u->no_resolve) {
|
sin->sin_port = htons(u->default_port);
|
||||||
u->port = u->default_port;
|
|
||||||
sin->sin_port = htons(u->default_port);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
len = last - host;
|
len = last - host;
|
||||||
@ -868,11 +865,8 @@ ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
u->no_port = 1;
|
u->no_port = 1;
|
||||||
|
u->port = u->default_port;
|
||||||
if (!u->no_resolve) {
|
sin6->sin6_port = htons(u->default_port);
|
||||||
u->port = u->default_port;
|
|
||||||
sin6->sin6_port = htons(u->default_port);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4121,6 +4121,7 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
|||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
u.host = value[1];
|
u.host = value[1];
|
||||||
u.no_resolve = 1;
|
u.no_resolve = 1;
|
||||||
|
u.no_port = 1;
|
||||||
|
|
||||||
uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
|
uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
|
||||||
|NGX_HTTP_UPSTREAM_WEIGHT
|
|NGX_HTTP_UPSTREAM_WEIGHT
|
||||||
@ -4391,14 +4392,14 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && u->port) {
|
if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) {
|
||||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||||
"upstream \"%V\" may not have port %d",
|
"upstream \"%V\" may not have port %d",
|
||||||
&u->host, u->port);
|
&u->host, u->port);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & NGX_HTTP_UPSTREAM_CREATE) && uscfp[i]->port) {
|
if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) {
|
||||||
ngx_log_error(NGX_LOG_WARN, cf->log, 0,
|
ngx_log_error(NGX_LOG_WARN, cf->log, 0,
|
||||||
"upstream \"%V\" may not have port %d in %s:%ui",
|
"upstream \"%V\" may not have port %d in %s:%ui",
|
||||||
&u->host, uscfp[i]->port,
|
&u->host, uscfp[i]->port,
|
||||||
@ -4406,7 +4407,9 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uscfp[i]->port != u->port) {
|
if (uscfp[i]->port && u->port
|
||||||
|
&& uscfp[i]->port != u->port)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4434,6 +4437,7 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
|
|||||||
uscf->line = cf->conf_file->line;
|
uscf->line = cf->conf_file->line;
|
||||||
uscf->port = u->port;
|
uscf->port = u->port;
|
||||||
uscf->default_port = u->default_port;
|
uscf->default_port = u->default_port;
|
||||||
|
uscf->no_port = u->no_port;
|
||||||
|
|
||||||
if (u->naddrs == 1) {
|
if (u->naddrs == 1) {
|
||||||
uscf->servers = ngx_array_create(cf->pool, 1,
|
uscf->servers = ngx_array_create(cf->pool, 1,
|
||||||
|
@ -116,6 +116,7 @@ struct ngx_http_upstream_srv_conf_s {
|
|||||||
ngx_uint_t line;
|
ngx_uint_t line;
|
||||||
in_port_t port;
|
in_port_t port;
|
||||||
in_port_t default_port;
|
in_port_t default_port;
|
||||||
|
ngx_uint_t no_port; /* unsigned no_port:1 */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
|
|||||||
|
|
||||||
/* an upstream implicitly defined by proxy_pass, etc. */
|
/* an upstream implicitly defined by proxy_pass, etc. */
|
||||||
|
|
||||||
if (us->port == 0 && us->default_port == 0) {
|
if (us->port == 0) {
|
||||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||||
"no port in upstream \"%V\" in %s:%ui",
|
"no port in upstream \"%V\" in %s:%ui",
|
||||||
&us->host, us->file_name, us->line);
|
&us->host, us->file_name, us->line);
|
||||||
@ -171,7 +171,7 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
|
|||||||
ngx_memzero(&u, sizeof(ngx_url_t));
|
ngx_memzero(&u, sizeof(ngx_url_t));
|
||||||
|
|
||||||
u.host = us->host;
|
u.host = us->host;
|
||||||
u.port = (in_port_t) (us->port ? us->port : us->default_port);
|
u.port = us->port;
|
||||||
|
|
||||||
if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
|
if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
|
||||||
if (u.err) {
|
if (u.err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user