1

I use OpenResty® to proxy my backend server. The process is client->proxy server->backend server

The question is the comment of the code:

stream {
    upstream teststream{
        server xxxxxx:1234;
    }

    server {
        listen 1234;
        proxy_pass teststream;

        content_by_lua_block {
            #how to get the proxy server socket port between proxy server and backend server
        }
    }}

Client sends a message to proxy server, then proxy server forwards the message to backend server.The proxy server will new a socket to connect the backend server, so how to get the proxy server socket port between proxy server and backend server in content_by_lua_block?

4

1 回答 1

1

There is https://github.com/openresty/lua-upstream-nginx-module

get_servers

syntax: servers = upstream.get_servers(upstream_name)

Get configurations for all the servers in the specified upstream group. Please one server may take multiple addresses when its server name can be resolved to multiple addresses.

The return value is an array-like Lua table. Each table entry is a hash-like Lua table that takes the following keys:

  • addr

socket address(es). can be either a Lua string or an array-like Lua table of Lua strings.

...

BTW, both proxy_pass and content_by_lua_block are content phase directives. Only one will work. Please take a look at this post https://groups.google.com/forum/#!topic/openresty-en/DRocQpM4mVY

于 2017-04-06T08:03:58.403 回答