variable support for unix sockets in fastcgi_pass and proxy_pass

This commit is contained in:
Igor Sysoev 2008-12-23 19:35:12 +00:00
parent 8eb5ed2e77
commit 302cedceb0
5 changed files with 79 additions and 32 deletions

View File

@ -512,8 +512,16 @@ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
return NGX_ERROR; return NGX_ERROR;
} }
r->upstream->resolved->host = u.host; if (u.addrs[0].sockaddr) {
r->upstream->resolved->port = u.port; r->upstream->resolved->sockaddr = u.addrs[0].sockaddr;
r->upstream->resolved->socklen = u.addrs[0].socklen;
r->upstream->resolved->naddrs = 1;
r->upstream->resolved->host = u.addrs[0].name;
} else {
r->upstream->resolved->host = u.host;
r->upstream->resolved->port = u.port;
}
return NGX_OK; return NGX_OK;
} }

View File

@ -614,10 +614,18 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
return NGX_ERROR; return NGX_ERROR;
} }
r->upstream->resolved->host = u.host; if (u.addrs[0].sockaddr) {
r->upstream->resolved->port = (in_port_t) (u.no_port ? u.default_port: r->upstream->resolved->sockaddr = u.addrs[0].sockaddr;
u.port); r->upstream->resolved->socklen = u.addrs[0].socklen;
r->upstream->resolved->no_port = u.no_port; r->upstream->resolved->naddrs = 1;
r->upstream->resolved->host = u.addrs[0].name;
} else {
r->upstream->resolved->host = u.host;
r->upstream->resolved->port = (in_port_t) (u.no_port ? u.default_port:
u.port);
r->upstream->resolved->no_port = u.no_port;
}
return NGX_OK; return NGX_OK;
} }

View File

@ -414,6 +414,20 @@ ngx_http_upstream_init(ngx_http_request_t *r)
} else { } else {
if (u->resolved->sockaddr) {
if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
!= NGX_OK)
{
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
ngx_http_upstream_connect(r, u);
return;
}
host = &u->resolved->host; 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);

View File

@ -209,8 +209,13 @@ typedef struct {
ngx_str_t host; ngx_str_t host;
in_port_t port; in_port_t port;
ngx_uint_t no_port; /* unsigned no_port:1 */ ngx_uint_t no_port; /* unsigned no_port:1 */
ngx_uint_t naddrs; ngx_uint_t naddrs;
in_addr_t *addrs; in_addr_t *addrs;
struct sockaddr *sockaddr;
socklen_t socklen;
ngx_resolver_ctx_t *ctx; ngx_resolver_ctx_t *ctx;
} ngx_http_upstream_resolved_t; } ngx_http_upstream_resolved_t;

View File

@ -279,35 +279,47 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
peers->number = ur->naddrs; peers->number = ur->naddrs;
peers->name = &ur->host; peers->name = &ur->host;
for (i = 0; i < ur->naddrs; i++) { if (ur->sockaddr) {
peers->peer[0].sockaddr = ur->sockaddr;
peers->peer[0].socklen = ur->socklen;
peers->peer[0].name = ur->host;
peers->peer[0].weight = 1;
peers->peer[0].current_weight = 1;
peers->peer[0].max_fails = 1;
peers->peer[0].fail_timeout = 10;
len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1; } else {
p = ngx_pnalloc(r->pool, len); for (i = 0; i < ur->naddrs; i++) {
if (p == NULL) {
return NGX_ERROR; len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1;
p = ngx_pnalloc(r->pool, len);
if (p == NULL) {
return NGX_ERROR;
}
len = ngx_inet_ntop(AF_INET, &ur->addrs[i], p, NGX_INET_ADDRSTRLEN);
len = ngx_sprintf(&p[len], ":%d", ur->port) - p;
sin = ngx_pcalloc(r->pool, sizeof(struct sockaddr_in));
if (sin == NULL) {
return NGX_ERROR;
}
sin->sin_family = AF_INET;
sin->sin_port = htons(ur->port);
sin->sin_addr.s_addr = ur->addrs[i];
peers->peer[i].sockaddr = (struct sockaddr *) sin;
peers->peer[i].socklen = sizeof(struct sockaddr_in);
peers->peer[i].name.len = len;
peers->peer[i].name.data = p;
peers->peer[i].weight = 1;
peers->peer[i].current_weight = 1;
peers->peer[i].max_fails = 1;
peers->peer[i].fail_timeout = 10;
} }
len = ngx_inet_ntop(AF_INET, &ur->addrs[i], p, NGX_INET_ADDRSTRLEN);
len = ngx_sprintf(&p[len], ":%d", ur->port) - p;
sin = ngx_pcalloc(r->pool, sizeof(struct sockaddr_in));
if (sin == NULL) {
return NGX_ERROR;
}
sin->sin_family = AF_INET;
sin->sin_port = htons(ur->port);
sin->sin_addr.s_addr = ur->addrs[i];
peers->peer[i].sockaddr = (struct sockaddr *) sin;
peers->peer[i].socklen = sizeof(struct sockaddr_in);
peers->peer[i].name.len = len;
peers->peer[i].name.data = p;
peers->peer[i].weight = 1;
peers->peer[i].current_weight = 1;
peers->peer[i].max_fails = 1;
peers->peer[i].fail_timeout = 10;
} }
rrp->peers = peers; rrp->peers = peers;