Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems when the hostname is not an ip but a name defined in /etc/hosts (Docker) #45

Closed
ruslantalpa opened this issue Jun 13, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@ruslantalpa
Copy link

commented Jun 13, 2016

Given this config for upstream

upstream postgrest {
        server remotecomputer:3000;
        balancer_by_lua_block {
            local balancer = require 'ngx.balancer'
            local host = 'remotecomputer'
            local port = 3000
            local ok, err = balancer.set_current_peer(host, port)
            if not ok then
                ngx.log(ngx.ERR, 'failed to set the current peer ', err)
                return ngx.exit(500)
            end
        }
        keepalive 64;
}

I get the error

2016/06/13 10:47:54 [error] 5#5: *1 [lua] balancer_by_lua:8: failed to set the current peer no host allowed while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET /.... HTTP/1.1", host: "192.168.99.100:8080"

If i comment the whole balancer_by_lua_block everything works

Any idea what i'm doing wrong?
Thank you

@agentzh

This comment has been minimized.

Copy link
Member

commented Jun 13, 2016

@ruslantalpa I think the error message you are getting is already quite clear about the reason: set_current_peer does not support host names other than IP addresses.

You can, however, use the lua-resty-dns library in an earlier phase, like access_by_lua*, to resolve your domain names to IP addresses and save the IP addresses to ngx.ctx which can be later read in your balancer_by_lua*.

@agentzh

This comment has been minimized.

Copy link
Member

commented Jun 13, 2016

@ruslantalpa Oh, BTW, /etc/hosts is not supported (yet) in lua-resty-dns. So you'd better read that file yourself instead (but ensure you are caching the result otherwise reading a file upon every request can be quite expensive).

@ruslantalpa

This comment has been minimized.

Copy link
Author

commented Jun 13, 2016

That's the answer i was looking for, to make sure it's a limitation and not me doing something wrong.
Thank you.

@sempasha

This comment has been minimized.

Copy link

commented Jul 18, 2016

lua-resty-dns seems to be too complex for simple dns lookup. And there is no ``/etc/hosts` file support at all.

Is there any way to use something like nginx build in ngx_inet_resolve_host function?

@agentzh

This comment has been minimized.

Copy link
Member

commented Jul 18, 2016

@ruslantalpa Well, you can abstract out a simple Lua function atop lua-resty-dns for simple queries and you can parse /etc/hosts in Lua rather easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.