mirror of
https://github.com/nginx/nginx.git
synced 2024-12-12 18:29:00 +08:00
variable support for unix sockets in fastcgi_pass and proxy_pass
This commit is contained in:
parent
8eb5ed2e77
commit
302cedceb0
@ -512,8 +512,16 @@ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (u.addrs[0].sockaddr) {
|
||||
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;
|
||||
}
|
||||
|
@ -614,10 +614,18 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (u.addrs[0].sockaddr) {
|
||||
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 = (in_port_t) (u.no_port ? u.default_port:
|
||||
u.port);
|
||||
r->upstream->resolved->no_port = u.no_port;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
@ -414,6 +414,20 @@ ngx_http_upstream_init(ngx_http_request_t *r)
|
||||
|
||||
} 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;
|
||||
|
||||
umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
|
||||
|
@ -209,8 +209,13 @@ typedef struct {
|
||||
ngx_str_t host;
|
||||
in_port_t port;
|
||||
ngx_uint_t no_port; /* unsigned no_port:1 */
|
||||
|
||||
ngx_uint_t naddrs;
|
||||
in_addr_t *addrs;
|
||||
|
||||
struct sockaddr *sockaddr;
|
||||
socklen_t socklen;
|
||||
|
||||
ngx_resolver_ctx_t *ctx;
|
||||
} ngx_http_upstream_resolved_t;
|
||||
|
||||
|
@ -279,6 +279,17 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
|
||||
peers->number = ur->naddrs;
|
||||
peers->name = &ur->host;
|
||||
|
||||
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;
|
||||
|
||||
} else {
|
||||
|
||||
for (i = 0; i < ur->naddrs; i++) {
|
||||
|
||||
len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1;
|
||||
@ -309,6 +320,7 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
|
||||
peers->peer[i].max_fails = 1;
|
||||
peers->peer[i].fail_timeout = 10;
|
||||
}
|
||||
}
|
||||
|
||||
rrp->peers = peers;
|
||||
rrp->current = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user