aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_proxy_module.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2014-02-15 15:12:34 +0400
committerAleksei Bavshin <a.bavshin@f5.com>2024-11-07 07:57:42 -0800
commitdb6870e06dde7ab249e9a41a0e0a76219f82dd8c (patch)
treed24f1bb15d855a4a85f1240cc4bbbc9dbf6f74be /src/stream/ngx_stream_proxy_module.c
parentebd18ec1812bd6f3de54d9f9fc81563a0ec9f264 (diff)
downloadnginx-db6870e06dde7ab249e9a41a0e0a76219f82dd8c.tar.gz
nginx-db6870e06dde7ab249e9a41a0e0a76219f82dd8c.zip
Upstream: re-resolvable servers.
Specifying the upstream server by a hostname together with the "resolve" parameter will make the hostname to be periodically resolved, and upstream servers added/removed as necessary. This requires a "resolver" at the "http" configuration block. The "resolver_timeout" parameter also affects when the failed DNS requests will be attempted again. Responses with NXDOMAIN will be attempted again in 10 seconds. Upstream has a configuration generation number that is incremented each time servers are added/removed to the primary/backup list. This number is remembered by the peer.init method, and if peer.get detects a change in configuration, it returns NGX_BUSY. Each server has a reference counter. It is incremented by peer.get and decremented by peer.free. When a server is removed, it is removed from the list of servers and is marked as "zombie". The memory allocated by a zombie peer is freed only when its reference count becomes zero. Co-authored-by: Roman Arutyunyan <arut@nginx.com> Co-authored-by: Sergey Kandaurov <pluknet@nginx.com> Co-authored-by: Vladimir Homutov <vl@nginx.com>
Diffstat (limited to 'src/stream/ngx_stream_proxy_module.c')
-rw-r--r--src/stream/ngx_stream_proxy_module.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
index bbf4f7ec0..0890a04ae 100644
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -742,6 +742,25 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s)
u->state->peer = u->peer.name;
+#if (NGX_STREAM_UPSTREAM_ZONE)
+ if (u->upstream && u->upstream->shm_zone
+ && (u->upstream->flags & NGX_STREAM_UPSTREAM_MODIFY))
+ {
+ u->state->peer = ngx_palloc(s->connection->pool,
+ sizeof(ngx_str_t) + u->peer.name->len);
+ if (u->state->peer == NULL) {
+ ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ u->state->peer->len = u->peer.name->len;
+ u->state->peer->data = (u_char *) (u->state->peer + 1);
+ ngx_memcpy(u->state->peer->data, u->peer.name->data, u->peer.name->len);
+
+ u->peer.name = u->state->peer;
+ }
+#endif
+
if (rc == NGX_BUSY) {
ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams");
ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY);