summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2006-12-12 16:46:16 +0000
committerIgor Sysoev <igor@sysoev.ru>2006-12-12 16:46:16 +0000
commitbf3aaac7ac691d142201daaf7fa687d4760bbf22 (patch)
treeb8708eb68217a48d66762506c6d78c0b66227ec3 /src/http
parent63ba5a61b59142048400b0a5e434abb7c7b98e2a (diff)
downloadnginx-bf3aaac7ac691d142201daaf7fa687d4760bbf22.tar.gz
nginx-bf3aaac7ac691d142201daaf7fa687d4760bbf22.tar.bz2
rewritten upstream
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c1
-rw-r--r--src/http/modules/ngx_http_memcached_module.c1
-rw-r--r--src/http/modules/ngx_http_proxy_module.c50
-rw-r--r--src/http/ngx_http_core_module.c4
-rw-r--r--src/http/ngx_http_upstream.c29
-rw-r--r--src/http/ngx_http_upstream.h1
-rw-r--r--src/http/ngx_http_upstream_round_robin.c16
7 files changed, 73 insertions, 29 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index fdefb835c..ab214770e 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -2010,7 +2010,6 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(&u, sizeof(ngx_url_t));
u.url = value[1];
- u.upstream = 1;
u.no_resolve = 1;
lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
diff --git a/src/http/modules/ngx_http_memcached_module.c b/src/http/modules/ngx_http_memcached_module.c
index 5265c38cf..bd8b83716 100644
--- a/src/http/modules/ngx_http_memcached_module.c
+++ b/src/http/modules/ngx_http_memcached_module.c
@@ -583,7 +583,6 @@ ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(&u, sizeof(ngx_url_t));
u.url = value[1];
- u.upstream = 1;
u.no_resolve = 1;
/* u.uri_part = 1; may be used as namespace */
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index dbca2ab54..2c26df901 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -51,7 +51,7 @@ typedef struct {
ngx_str_t method;
ngx_str_t host_header;
- ngx_str_t port_text;
+ ngx_str_t port;
ngx_flag_t redirect;
} ngx_http_proxy_loc_conf_t;
@@ -1232,11 +1232,11 @@ ngx_http_proxy_port_variable(ngx_http_request_t *r,
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
- v->len = plcf->port_text.len;
+ v->len = plcf->port.len;
v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
- v->data = plcf->port_text.data;
+ v->data = plcf->port.data;
return NGX_OK;
}
@@ -1817,7 +1817,7 @@ peers:
conf->upstream.upstream = prev->upstream.upstream;
conf->host_header = prev->host_header;
- conf->port_text = prev->port_text;
+ conf->port = prev->port;
conf->upstream.schema = prev->upstream.schema;
}
@@ -2093,6 +2093,7 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_proxy_loc_conf_t *plcf = conf;
+ u_char *p;
size_t add;
u_short port;
ngx_str_t *value, *url;
@@ -2158,18 +2159,49 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
u.url.len = url->len - add;
u.url.data = url->data + add;
- u.default_portn = port;
- u.upstream = 1;
- u.no_resolve = 1;
+ u.default_port = port;
u.uri_part = 1;
+ u.no_resolve = 1;
plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
if (plcf->upstream.upstream == NULL) {
return NGX_CONF_ERROR;
}
- plcf->host_header = u.host_header;
- plcf->port_text = u.port;
+ if (!u.unix_socket) {
+ if (u.no_port || u.port == port) {
+ plcf->host_header = u.host;
+
+ if (port == 80) {
+ plcf->port.len = sizeof("80") - 1;
+ plcf->port.data = (u_char *) "80";
+ } else {
+ plcf->port.len = sizeof("443") - 1;
+ plcf->port.data = (u_char *) "443";
+ }
+
+ } else {
+ p = ngx_palloc(cf->pool, u.host.len + sizeof(":65536") - 1);
+ if (p == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ plcf->host_header.len = ngx_sprintf(p, "%V:%d", &u.host, u.port)
+ - p;
+ plcf->host_header.data = p;
+
+ plcf->port.len = plcf->host_header.len - u.host.len - 1;
+ plcf->port.data = p + u.host.len + 1;
+ }
+
+
+ } else {
+ plcf->host_header.len = sizeof("localhost") - 1;
+ plcf->host_header.data = (u_char *) "localhost";
+ plcf->port.len = 0;
+ plcf->port.data = (u_char *) "";
+ }
+
plcf->upstream.uri = u.uri;
plcf->upstream.schema.len = add;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 7f12daef1..34149c49f 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2390,7 +2390,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
u.url = value[1];
u.listen = 1;
- u.default_portn = 80;
+ u.default_port = 80;
if (ngx_parse_url(cf, &u) != NGX_OK) {
if (u.err) {
@@ -2411,7 +2411,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ls->family = AF_INET;
ls->addr = u.addr.in_addr;
- ls->port = u.portn;
+ ls->port = u.port;
ls->file_name = cf->conf_file->file.name;
ls->line = cf->conf_file->line;
ls->conf.backlog = -1;
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index a917dcf49..00fa4575e 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2598,7 +2598,6 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
value = cf->args->elts;
u.host = value[1];
- u.upstream = 1;
u.no_resolve = 1;
uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
@@ -2722,7 +2721,7 @@ ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(&u, sizeof(ngx_url_t));
u.url = value[1];
- u.default_portn = 80;
+ u.default_port = 80;
if (ngx_parse_url(cf, &u) != NGX_OK) {
if (u.err) {
@@ -2843,8 +2842,8 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
uscfp = umcf->upstreams.elts;
for (i = 0; i < umcf->upstreams.nelts; i++) {
- if ((uscfp[i]->port && uscfp[i]->port != u->portn)
- || uscfp[i]->host.len != u->host.len
+
+ if (uscfp[i]->host.len != u->host.len
|| ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len)
!= 0)
{
@@ -2859,10 +2858,23 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
return NULL;
}
- if (uscfp[i]->port == 0 && u->portn && !u->no_port) {
+ if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && u->port) {
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
- "upstream \"%V\" port %d is ignored",
- &u->host, u->portn);
+ "upstream \"%V\" may not have port %d",
+ &u->host, u->port);
+ return NULL;
+ }
+
+ if ((flags & NGX_HTTP_UPSTREAM_CREATE) && uscfp[i]->port) {
+ ngx_log_error(NGX_LOG_WARN, cf->log, 0,
+ "upstream \"%V\" may not have port %d in %s:%ui",
+ &u->host, uscfp[i]->port,
+ uscfp[i]->file_name.data, uscfp[i]->line);
+ return NULL;
+ }
+
+ if (uscfp[i]->port != u->port) {
+ continue;
}
return uscfp[i];
@@ -2877,7 +2889,8 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
uscf->host = u->host;
uscf->file_name = cf->conf_file->file.name;
uscf->line = cf->conf_file->line;
- uscf->port = u->portn;
+ uscf->port = u->port;
+ uscf->default_port = u->default_port;
if (u->naddrs == 1) {
uscf->servers = ngx_array_create(cf->pool, 1,
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index 185964e2c..aa5cc3518 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -94,6 +94,7 @@ struct ngx_http_upstream_srv_conf_s {
ngx_str_t file_name;
ngx_uint_t line;
in_port_t port;
+ in_port_t default_port;
};
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
index 82173e4b0..89937efde 100644
--- a/src/http/ngx_http_upstream_round_robin.c
+++ b/src/http/ngx_http_upstream_round_robin.c
@@ -61,10 +61,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
/* an upstream implicitly defined by proxy_pass, etc. */
+ if (us->port == 0 && us->default_port == 0) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "no port in upstream \"%V\" in %s:%ui",
+ &us->host, us->file_name.data, us->line);
+ return NGX_ERROR;
+ }
+
ngx_memzero(&u, sizeof(ngx_url_t));
u.host = us->host;
- u.portn = us->port;
+ u.port = us->port ? us->port : us->default_port;
if (ngx_inet_resolve_host(cf, &u) != NGX_OK) {
if (u.err) {
@@ -76,13 +83,6 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
return NGX_ERROR;
}
- if (us->port == 0) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no port in upstream \"%V\" in %s:%ui",
- &us->host, us->file_name.data, us->line);
- return NGX_ERROR;
- }
-
n = u.naddrs;
peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)