upstream and proxy_pass behavior

Maxim Dounin mdounin at mdounin.ru
Fri Sep 23 18:59:33 UTC 2016


Hello!

On Fri, Sep 23, 2016 at 11:38:44AM -0500, Philip Walenta wrote:

[...]

> I see an error of:
> 
> *51 no resolver defined to resolve origin.9999, client: 5.6.7.8, server:
> www.example.com, request: "GET /api/v1/proxy/?tid=9999 HTTP/1.1", host: "
> www.example.com" - as if it only considers a DNS lookup, even though there
> is an upstream server block configured.

[...]

> Is there a reason the first example isn't working?
> 
> It's very valuable to me to be able to pass the port to the upstream server
> as shown in the second example as it reduces the number of upstream blocks
> I need by a factor of 10 or more.

When using upstream groups as defined using the upstream{} 
directive, ports are specified on per-server basis in the "server"
directives of the upstream group.  If there is no port explicitly 
specified, it just means that port 80 will be used by default.  

If you'll try something like this, without variables:

    upstream u {
        server 127.0.0.1;
    }

    proxy_pass http://u:8080;

then nginx will complain right during configuration parsing:

nginx: [emerg] upstream "u" may not have port 8081 in ...

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list