Klaus Demo nginx / 302cedc
variable support for unix sockets in fastcgi_pass and proxy_pass Igor Sysoev 13 years ago
5 changed file(s) with 82 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
511511 return NGX_ERROR;
512512 }
513513
514 r->upstream->resolved->host = u.host;
515 r->upstream->resolved->port = u.port;
514 if (u.addrs[0].sockaddr) {
515 r->upstream->resolved->sockaddr = u.addrs[0].sockaddr;
516 r->upstream->resolved->socklen = u.addrs[0].socklen;
517 r->upstream->resolved->naddrs = 1;
518 r->upstream->resolved->host = u.addrs[0].name;
519
520 } else {
521 r->upstream->resolved->host = u.host;
522 r->upstream->resolved->port = u.port;
523 }
516524
517525 return NGX_OK;
518526 }
613613 return NGX_ERROR;
614614 }
615615
616 r->upstream->resolved->host = u.host;
617 r->upstream->resolved->port = (in_port_t) (u.no_port ? u.default_port:
618 u.port);
619 r->upstream->resolved->no_port = u.no_port;
616 if (u.addrs[0].sockaddr) {
617 r->upstream->resolved->sockaddr = u.addrs[0].sockaddr;
618 r->upstream->resolved->socklen = u.addrs[0].socklen;
619 r->upstream->resolved->naddrs = 1;
620 r->upstream->resolved->host = u.addrs[0].name;
621
622 } else {
623 r->upstream->resolved->host = u.host;
624 r->upstream->resolved->port = (in_port_t) (u.no_port ? u.default_port:
625 u.port);
626 r->upstream->resolved->no_port = u.no_port;
627 }
620628
621629 return NGX_OK;
622630 }
413413
414414 } else {
415415
416 if (u->resolved->sockaddr) {
417
418 if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
419 != NGX_OK)
420 {
421 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
422 return;
423 }
424
425 ngx_http_upstream_connect(r, u);
426
427 return;
428 }
429
416430 host = &u->resolved->host;
417431
418432 umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
208208 ngx_str_t host;
209209 in_port_t port;
210210 ngx_uint_t no_port; /* unsigned no_port:1 */
211
211212 ngx_uint_t naddrs;
212213 in_addr_t *addrs;
214
215 struct sockaddr *sockaddr;
216 socklen_t socklen;
217
213218 ngx_resolver_ctx_t *ctx;
214219 } ngx_http_upstream_resolved_t;
215220
278278 peers->number = ur->naddrs;
279279 peers->name = &ur->host;
280280
281 for (i = 0; i < ur->naddrs; i++) {
282
283 len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1;
284
285 p = ngx_pnalloc(r->pool, len);
286 if (p == NULL) {
287 return NGX_ERROR;
288 }
289
290 len = ngx_inet_ntop(AF_INET, &ur->addrs[i], p, NGX_INET_ADDRSTRLEN);
291 len = ngx_sprintf(&p[len], ":%d", ur->port) - p;
292
293 sin = ngx_pcalloc(r->pool, sizeof(struct sockaddr_in));
294 if (sin == NULL) {
295 return NGX_ERROR;
296 }
297
298 sin->sin_family = AF_INET;
299 sin->sin_port = htons(ur->port);
300 sin->sin_addr.s_addr = ur->addrs[i];
301
302 peers->peer[i].sockaddr = (struct sockaddr *) sin;
303 peers->peer[i].socklen = sizeof(struct sockaddr_in);
304 peers->peer[i].name.len = len;
305 peers->peer[i].name.data = p;
306 peers->peer[i].weight = 1;
307 peers->peer[i].current_weight = 1;
308 peers->peer[i].max_fails = 1;
309 peers->peer[i].fail_timeout = 10;
281 if (ur->sockaddr) {
282 peers->peer[0].sockaddr = ur->sockaddr;
283 peers->peer[0].socklen = ur->socklen;
284 peers->peer[0].name = ur->host;
285 peers->peer[0].weight = 1;
286 peers->peer[0].current_weight = 1;
287 peers->peer[0].max_fails = 1;
288 peers->peer[0].fail_timeout = 10;
289
290 } else {
291
292 for (i = 0; i < ur->naddrs; i++) {
293
294 len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1;
295
296 p = ngx_pnalloc(r->pool, len);
297 if (p == NULL) {
298 return NGX_ERROR;
299 }
300
301 len = ngx_inet_ntop(AF_INET, &ur->addrs[i], p, NGX_INET_ADDRSTRLEN);
302 len = ngx_sprintf(&p[len], ":%d", ur->port) - p;
303
304 sin = ngx_pcalloc(r->pool, sizeof(struct sockaddr_in));
305 if (sin == NULL) {
306 return NGX_ERROR;
307 }
308
309 sin->sin_family = AF_INET;
310 sin->sin_port = htons(ur->port);
311 sin->sin_addr.s_addr = ur->addrs[i];
312
313 peers->peer[i].sockaddr = (struct sockaddr *) sin;
314 peers->peer[i].socklen = sizeof(struct sockaddr_in);
315 peers->peer[i].name.len = len;
316 peers->peer[i].name.data = p;
317 peers->peer[i].weight = 1;
318 peers->peer[i].current_weight = 1;
319 peers->peer[i].max_fails = 1;
320 peers->peer[i].fail_timeout = 10;
321 }
310322 }
311323
312324 rrp->peers = peers;