mirror of
https://github.com/nginx/nginx.git
synced 2024-12-04 22:09:01 +08:00
proxy_bind, fastcgi_bind, and memcached_bind
This commit is contained in:
parent
1d52beba73
commit
72e928755b
@ -54,15 +54,7 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
{
|
{
|
||||||
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
||||||
"setsockopt(SO_RCVBUF) failed");
|
"setsockopt(SO_RCVBUF) failed");
|
||||||
|
goto failed;
|
||||||
ngx_free_connection(c);
|
|
||||||
|
|
||||||
if (ngx_close_socket(s) == -1) {
|
|
||||||
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
|
||||||
ngx_close_socket_n " failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +62,16 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
||||||
ngx_nonblocking_n " failed");
|
ngx_nonblocking_n " failed");
|
||||||
|
|
||||||
ngx_free_connection(c);
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
if (ngx_close_socket(s) == -1) {
|
if (pc->local) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) {
|
||||||
ngx_close_socket_n " failed");
|
ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno,
|
||||||
|
"bind(%V) failed", &pc->local->name);
|
||||||
|
|
||||||
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NGX_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c->recv = ngx_recv;
|
c->recv = ngx_recv;
|
||||||
@ -127,7 +121,7 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
|
|
||||||
if (ngx_add_conn) {
|
if (ngx_add_conn) {
|
||||||
if (ngx_add_conn(c) == NGX_ERROR) {
|
if (ngx_add_conn(c) == NGX_ERROR) {
|
||||||
return NGX_ERROR;
|
goto failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +193,7 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
if (ngx_blocking(s) == -1) {
|
if (ngx_blocking(s) == -1) {
|
||||||
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
||||||
ngx_blocking_n " failed");
|
ngx_blocking_n " failed");
|
||||||
return NGX_ERROR;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -229,7 +223,7 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) {
|
if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) {
|
||||||
return NGX_ERROR;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
@ -237,7 +231,7 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
/* NGX_EINPROGRESS */
|
/* NGX_EINPROGRESS */
|
||||||
|
|
||||||
if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) {
|
if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) {
|
||||||
return NGX_ERROR;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NGX_AGAIN;
|
return NGX_AGAIN;
|
||||||
@ -248,6 +242,17 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
|||||||
wev->ready = 1;
|
wev->ready = 1;
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
|
||||||
|
failed:
|
||||||
|
|
||||||
|
ngx_free_connection(c);
|
||||||
|
|
||||||
|
if (ngx_close_socket(s) == -1) {
|
||||||
|
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
||||||
|
ngx_close_socket_n " failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ struct ngx_peer_connection_s {
|
|||||||
ngx_atomic_t *lock;
|
ngx_atomic_t *lock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ngx_addr_t *local;
|
||||||
|
|
||||||
int rcvbuf;
|
int rcvbuf;
|
||||||
|
|
||||||
ngx_log_t *log;
|
ngx_log_t *log;
|
||||||
|
@ -240,6 +240,13 @@ static ngx_command_t ngx_http_fastcgi_commands[] = {
|
|||||||
offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_client_abort),
|
offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_client_abort),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("fastcgi_bind"),
|
||||||
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
|
ngx_http_upsteam_bind_set_slot,
|
||||||
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
|
offsetof(ngx_http_fastcgi_loc_conf_t, upstream.local),
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("fastcgi_connect_timeout"),
|
{ ngx_string("fastcgi_connect_timeout"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_msec_slot,
|
ngx_conf_set_msec_slot,
|
||||||
|
@ -63,6 +63,13 @@ static ngx_command_t ngx_http_memcached_commands[] = {
|
|||||||
0,
|
0,
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("memcached_bind"),
|
||||||
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
|
ngx_http_upsteam_bind_set_slot,
|
||||||
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
|
offsetof(ngx_http_memcached_loc_conf_t, upstream.local),
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("memcached_connect_timeout"),
|
{ ngx_string("memcached_connect_timeout"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_msec_slot,
|
ngx_conf_set_msec_slot,
|
||||||
|
@ -229,6 +229,13 @@ static ngx_command_t ngx_http_proxy_commands[] = {
|
|||||||
offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort),
|
offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("proxy_bind"),
|
||||||
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
|
ngx_http_upsteam_bind_set_slot,
|
||||||
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
|
offsetof(ngx_http_proxy_loc_conf_t, upstream.local),
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("proxy_connect_timeout"),
|
{ ngx_string("proxy_connect_timeout"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_msec_slot,
|
ngx_conf_set_msec_slot,
|
||||||
|
@ -479,6 +479,8 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u->peer.local = u->conf->local;
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
u->output.alignment = clcf->directio_alignment;
|
u->output.alignment = clcf->directio_alignment;
|
||||||
@ -4196,6 +4198,31 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
ngx_http_upsteam_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
|
void *conf)
|
||||||
|
{
|
||||||
|
char *p = conf;
|
||||||
|
|
||||||
|
ngx_str_t *value;
|
||||||
|
ngx_addr_t **paddr;
|
||||||
|
|
||||||
|
paddr = (ngx_addr_t **) (p + cmd->offset);
|
||||||
|
|
||||||
|
value = cf->args->elts;
|
||||||
|
|
||||||
|
*paddr = ngx_parse_addr(cf->pool, &value[1]);
|
||||||
|
if (*paddr) {
|
||||||
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"invalid address \"%V\"", &value[1]);
|
||||||
|
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t
|
ngx_int_t
|
||||||
ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
|
ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
|
||||||
ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
|
ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
|
||||||
|
@ -152,6 +152,8 @@ typedef struct {
|
|||||||
ngx_array_t *hide_headers;
|
ngx_array_t *hide_headers;
|
||||||
ngx_array_t *pass_headers;
|
ngx_array_t *pass_headers;
|
||||||
|
|
||||||
|
ngx_addr_t *local;
|
||||||
|
|
||||||
#if (NGX_HTTP_CACHE)
|
#if (NGX_HTTP_CACHE)
|
||||||
ngx_shm_zone_t *cache;
|
ngx_shm_zone_t *cache;
|
||||||
|
|
||||||
@ -321,6 +323,8 @@ ngx_int_t ngx_http_upstream_create(ngx_http_request_t *r);
|
|||||||
void ngx_http_upstream_init(ngx_http_request_t *r);
|
void ngx_http_upstream_init(ngx_http_request_t *r);
|
||||||
ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
|
ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
|
||||||
ngx_url_t *u, ngx_uint_t flags);
|
ngx_url_t *u, ngx_uint_t flags);
|
||||||
|
char *ngx_http_upsteam_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
|
void *conf);
|
||||||
ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
|
ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
|
||||||
ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
|
ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
|
||||||
ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
|
ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
|
||||||
|
Loading…
Reference in New Issue
Block a user