proxy_bind with hostname from /etc/hosts possible?

Francis Daly francis at
Fri Mar 17 14:51:44 UTC 2017

On Mon, Mar 13, 2017 at 10:38:12AM -0400, larsg wrote:

Hi there,

> is it possible to use an hostname from local /etc/hosts as proxy_bind
> value? says that its argument is an address. So
I'm going to say "no".

> You can see our current configuration above.
> Unfortunately nginx cannot resolve the hostname (localip0 etc.). There is an
> error log "invalid local address "localip0"...).

If you dive into the source code, you'll see that that error message
happens when a call to "ngx_parse_addr_port()" fails; and that function
does what its name suggests.

> I'm worry that I only can use explicit IP addresses in this situation. Or do
> you have an alternative solution?

I think you'll need to use IP addresses.

An option (untested) could be to put the split_clients call into an
external file which you "include" in your common nginx.conf, and let
*that* file be generated unique per host.

And another option could be to have a common nginx-conf-precursor
which is distributed to all hosts, and then run a pre-processor of your
choice against it to create the individual unique nginx.conf files.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list