Latest update - GitHub 569948a
This commit is contained in:
@@ -22,6 +22,11 @@ static char *ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *dummy);
|
||||
static char *ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
static char *ngx_stream_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
#endif
|
||||
|
||||
static void *ngx_stream_upstream_create_main_conf(ngx_conf_t *cf);
|
||||
static char *ngx_stream_upstream_init_main_conf(ngx_conf_t *cf, void *conf);
|
||||
|
||||
@@ -42,6 +47,24 @@ static ngx_command_t ngx_stream_upstream_commands[] = {
|
||||
0,
|
||||
NULL },
|
||||
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
|
||||
{ ngx_string("resolver"),
|
||||
NGX_STREAM_UPS_CONF|NGX_CONF_1MORE,
|
||||
ngx_stream_upstream_resolver,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("resolver_timeout"),
|
||||
NGX_STREAM_UPS_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_msec_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_upstream_srv_conf_t, resolver_timeout),
|
||||
NULL },
|
||||
|
||||
#endif
|
||||
|
||||
ngx_null_command
|
||||
};
|
||||
|
||||
@@ -319,6 +342,7 @@ ngx_stream_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
|
||||
u.no_port = 1;
|
||||
|
||||
uscf = ngx_stream_upstream_add(cf, &u, NGX_STREAM_UPSTREAM_CREATE
|
||||
|NGX_STREAM_UPSTREAM_MODIFY
|
||||
|NGX_STREAM_UPSTREAM_WEIGHT
|
||||
|NGX_STREAM_UPSTREAM_MAX_CONNS
|
||||
|NGX_STREAM_UPSTREAM_MAX_FAILS
|
||||
@@ -408,6 +432,9 @@ ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
ngx_url_t u;
|
||||
ngx_int_t weight, max_conns, max_fails;
|
||||
ngx_uint_t i;
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
ngx_uint_t resolve;
|
||||
#endif
|
||||
ngx_stream_upstream_server_t *us;
|
||||
|
||||
us = ngx_array_push(uscf->servers);
|
||||
@@ -423,6 +450,9 @@ ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
max_conns = 0;
|
||||
max_fails = 1;
|
||||
fail_timeout = 10;
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
resolve = 0;
|
||||
#endif
|
||||
|
||||
for (i = 2; i < cf->args->nelts; i++) {
|
||||
|
||||
@@ -511,6 +541,26 @@ ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
continue;
|
||||
}
|
||||
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
if (ngx_strcmp(value[i].data, "resolve") == 0) {
|
||||
resolve = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strncmp(value[i].data, "service=", 8) == 0) {
|
||||
|
||||
us->service.len = value[i].len - 8;
|
||||
us->service.data = &value[i].data[8];
|
||||
|
||||
if (us->service.len == 0) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "service is empty");
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
@@ -518,6 +568,22 @@ ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
|
||||
u.url = value[1];
|
||||
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
if (resolve) {
|
||||
/* resolve at run time */
|
||||
u.no_resolve = 1;
|
||||
}
|
||||
|
||||
if (us->service.len && !resolve) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"service upstream \"%V\" requires "
|
||||
"\"resolve\" parameter",
|
||||
&u.url);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
|
||||
if (u.err) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
@@ -527,15 +593,73 @@ ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (u.no_port) {
|
||||
if (u.no_port
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
&& us->service.len == 0
|
||||
#endif
|
||||
)
|
||||
{
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"no port in upstream \"%V\"", &u.url);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
us->name = u.url;
|
||||
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
|
||||
if (us->service.len && !u.no_port) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"service upstream \"%V\" may not have port",
|
||||
&us->name);
|
||||
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (us->service.len && u.naddrs) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"service upstream \"%V\" requires domain name",
|
||||
&us->name);
|
||||
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (resolve && u.naddrs == 0) {
|
||||
ngx_addr_t *addr;
|
||||
|
||||
/* save port */
|
||||
|
||||
addr = ngx_pcalloc(cf->pool, sizeof(ngx_addr_t));
|
||||
if (addr == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
addr->sockaddr = ngx_palloc(cf->pool, u.socklen);
|
||||
if (addr->sockaddr == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ngx_memcpy(addr->sockaddr, &u.sockaddr, u.socklen);
|
||||
|
||||
addr->socklen = u.socklen;
|
||||
|
||||
us->addrs = addr;
|
||||
us->naddrs = 1;
|
||||
|
||||
us->host = u.host;
|
||||
|
||||
} else {
|
||||
us->addrs = u.addrs;
|
||||
us->naddrs = u.naddrs;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
us->addrs = u.addrs;
|
||||
us->naddrs = u.naddrs;
|
||||
|
||||
#endif
|
||||
|
||||
us->weight = weight;
|
||||
us->max_conns = max_conns;
|
||||
us->max_fails = max_fails;
|
||||
@@ -560,6 +684,32 @@ not_supported:
|
||||
}
|
||||
|
||||
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
|
||||
static char *
|
||||
ngx_stream_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_stream_upstream_srv_conf_t *uscf = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
|
||||
if (uscf->resolver) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
uscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
|
||||
if (uscf->resolver == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
ngx_stream_upstream_srv_conf_t *
|
||||
ngx_stream_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
|
||||
{
|
||||
@@ -638,6 +788,9 @@ ngx_stream_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
|
||||
uscf->line = cf->conf_file->line;
|
||||
uscf->port = u->port;
|
||||
uscf->no_port = u->no_port;
|
||||
#if (NGX_STREAM_UPSTREAM_ZONE)
|
||||
uscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
|
||||
#endif
|
||||
|
||||
if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {
|
||||
uscf->servers = ngx_array_create(cf->pool, 1,
|
||||
|
||||
Reference in New Issue
Block a user