mirror of
https://github.com/nginx/nginx.git
synced 2025-06-06 00:42:40 +08:00
Stream: the "proxy_bind" directive.
This commit is contained in:
parent
ff0e31d7c7
commit
f50f83a2cf
@ -21,6 +21,7 @@ typedef struct {
|
||||
size_t upstream_buf_size;
|
||||
ngx_uint_t next_upstream_tries;
|
||||
ngx_flag_t next_upstream;
|
||||
ngx_addr_t *local;
|
||||
|
||||
#if (NGX_STREAM_SSL)
|
||||
ngx_flag_t ssl_enable;
|
||||
@ -64,6 +65,8 @@ static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent,
|
||||
void *child);
|
||||
static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
|
||||
#if (NGX_STREAM_SSL)
|
||||
|
||||
@ -97,6 +100,13 @@ static ngx_command_t ngx_stream_proxy_commands[] = {
|
||||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("proxy_bind"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_stream_proxy_bind,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("proxy_connect_timeout"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_msec_slot,
|
||||
@ -301,6 +311,8 @@ ngx_stream_proxy_handler(ngx_stream_session_t *s)
|
||||
u->peer.log = c->log;
|
||||
u->peer.log_error = NGX_ERROR_ERR;
|
||||
|
||||
u->peer.local = pscf->local;
|
||||
|
||||
uscf = pscf->upstream;
|
||||
|
||||
if (uscf->peer.init(s, uscf) != NGX_OK) {
|
||||
@ -1093,6 +1105,7 @@ ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf)
|
||||
conf->upstream_buf_size = NGX_CONF_UNSET_SIZE;
|
||||
conf->next_upstream_tries = NGX_CONF_UNSET_UINT;
|
||||
conf->next_upstream = NGX_CONF_UNSET;
|
||||
conf->local = NGX_CONF_UNSET_PTR;
|
||||
|
||||
#if (NGX_STREAM_SSL)
|
||||
conf->ssl_enable = NGX_CONF_UNSET;
|
||||
@ -1133,6 +1146,8 @@ ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
|
||||
ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1);
|
||||
|
||||
ngx_conf_merge_ptr_value(conf->local, prev->local, NULL);
|
||||
|
||||
#if (NGX_STREAM_SSL)
|
||||
|
||||
ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0);
|
||||
@ -1290,3 +1305,45 @@ ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_stream_proxy_srv_conf_t *pscf = conf;
|
||||
|
||||
ngx_int_t rc;
|
||||
ngx_str_t *value;
|
||||
|
||||
if (pscf->local != NGX_CONF_UNSET_PTR) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (ngx_strcmp(value[1].data, "off") == 0) {
|
||||
pscf->local = NULL;
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
pscf->local = ngx_palloc(cf->pool, sizeof(ngx_addr_t));
|
||||
if (pscf->local == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
rc = ngx_parse_addr(cf->pool, pscf->local, value[1].data, value[1].len);
|
||||
|
||||
switch (rc) {
|
||||
case NGX_OK:
|
||||
pscf->local->name = value[1];
|
||||
return NGX_CONF_OK;
|
||||
|
||||
case NGX_DECLINED:
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"invalid address \"%V\"", &value[1]);
|
||||
/* fall through */
|
||||
|
||||
default:
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user