comparison src/http/ngx_http_upstream.c @ 5005:c9059bd5445b

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.
author Ruslan Ermilov <ru@nginx.com>
date Thu, 10 Jan 2013 12:58:55 +0000
parents e2794322ec76
children fd84344f1df7
comparison
equal deleted inserted replaced
5004:764833756dcd 5005:c9059bd5445b
4119 ngx_memzero(&u, sizeof(ngx_url_t)); 4119 ngx_memzero(&u, sizeof(ngx_url_t));
4120 4120
4121 value = cf->args->elts; 4121 value = cf->args->elts;
4122 u.host = value[1]; 4122 u.host = value[1];
4123 u.no_resolve = 1; 4123 u.no_resolve = 1;
4124 u.no_port = 1;
4124 4125
4125 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE 4126 uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
4126 |NGX_HTTP_UPSTREAM_WEIGHT 4127 |NGX_HTTP_UPSTREAM_WEIGHT
4127 |NGX_HTTP_UPSTREAM_MAX_FAILS 4128 |NGX_HTTP_UPSTREAM_MAX_FAILS
4128 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT 4129 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
4389 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 4390 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4390 "duplicate upstream \"%V\"", &u->host); 4391 "duplicate upstream \"%V\"", &u->host);
4391 return NULL; 4392 return NULL;
4392 } 4393 }
4393 4394
4394 if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && u->port) { 4395 if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) {
4395 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, 4396 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
4396 "upstream \"%V\" may not have port %d", 4397 "upstream \"%V\" may not have port %d",
4397 &u->host, u->port); 4398 &u->host, u->port);
4398 return NULL; 4399 return NULL;
4399 } 4400 }
4400 4401
4401 if ((flags & NGX_HTTP_UPSTREAM_CREATE) && uscfp[i]->port) { 4402 if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) {
4402 ngx_log_error(NGX_LOG_WARN, cf->log, 0, 4403 ngx_log_error(NGX_LOG_WARN, cf->log, 0,
4403 "upstream \"%V\" may not have port %d in %s:%ui", 4404 "upstream \"%V\" may not have port %d in %s:%ui",
4404 &u->host, uscfp[i]->port, 4405 &u->host, uscfp[i]->port,
4405 uscfp[i]->file_name, uscfp[i]->line); 4406 uscfp[i]->file_name, uscfp[i]->line);
4406 return NULL; 4407 return NULL;
4407 } 4408 }
4408 4409
4409 if (uscfp[i]->port != u->port) { 4410 if (uscfp[i]->port && u->port
4411 && uscfp[i]->port != u->port)
4412 {
4410 continue; 4413 continue;
4411 } 4414 }
4412 4415
4413 if (uscfp[i]->default_port && u->default_port 4416 if (uscfp[i]->default_port && u->default_port
4414 && uscfp[i]->default_port != u->default_port) 4417 && uscfp[i]->default_port != u->default_port)
4432 uscf->host = u->host; 4435 uscf->host = u->host;
4433 uscf->file_name = cf->conf_file->file.name.data; 4436 uscf->file_name = cf->conf_file->file.name.data;
4434 uscf->line = cf->conf_file->line; 4437 uscf->line = cf->conf_file->line;
4435 uscf->port = u->port; 4438 uscf->port = u->port;
4436 uscf->default_port = u->default_port; 4439 uscf->default_port = u->default_port;
4440 uscf->no_port = u->no_port;
4437 4441
4438 if (u->naddrs == 1) { 4442 if (u->naddrs == 1) {
4439 uscf->servers = ngx_array_create(cf->pool, 1, 4443 uscf->servers = ngx_array_create(cf->pool, 1,
4440 sizeof(ngx_http_upstream_server_t)); 4444 sizeof(ngx_http_upstream_server_t));
4441 if (uscf->servers == NULL) { 4445 if (uscf->servers == NULL) {