Issue with upstream

Maxim Dounin mdounin at mdounin.ru
Thu Jan 6 10:59:55 MSK 2011


Hello!

On Tue, Nov 16, 2010 at 05:49:16PM +0300, Maxim Dounin wrote:

[...]

> Most likely you used backend2 somewhere in proxy_pass before 
> defining upstream backend2.  This is not generally supported and 
> and shouldn't be allowed, but happens to "work" (though with 
> several unexpected side effects) for now.

Disregard this (and patch).  Actually, the only thing which won't 
work as expected is an attempt to redefine unix socket with 
upstream{} block.

New patch attached.

Maxim Dounin
-------------- next part --------------
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1294300660 -10800
# Node ID b44ea37346fc2107a14a78a61cdb7d1866fdfa77
# Parent  aab3af62ad3bbaee7bab6c6425074cfb5bc6973a
Better handle late upstream creation.

Configuration with duplicate upstream blocks defined after first use, i.e.
like

    server {
        ...
        location / {
            proxy_pass http://backend;
        }
    }

    upstream backend { ... }
    upstream backend { ... }

now correctly results in "duplicate upstream" error.

Additionally, upstream blocks defined after first use now handle various
server directive parameters ("weight", "max_fails", etc.).  Previously
configuration like

    server {
        ...
        location / {
            proxy_pass http://backend;
        }
    }

    upstream backend {
        server 127.0.0.1 max_fails=5;
    }

incorrectly resulted in "invalid parameter "max_fails=5"" error.

Note that an attempt to redefine unix socket would produce unexpected
results.  Config like

    server {
        ...
        location / {
            proxy_pass http://unix:/path/to/socket;
        }
    }

    upstream "/path/to/socket" {
        server 127.0.0.1;
    }

would use upstream with two servers: one with unix socket "/path/to/socket",
and one 127.0.0.1.

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -4245,6 +4245,10 @@ ngx_http_upstream_add(ngx_conf_t *cf, ng
             continue;
         }
 
+        if (flags & NGX_HTTP_UPSTREAM_CREATE) {
+            uscfp[i]->flags = flags;
+        }
+
         return uscfp[i];
     }
 


More information about the nginx mailing list