Openresty如何在代理服务器和上游服务器之间获取代理服务器中的套接字端口?

How can Openresty get the socket port in proxy server between prroxy server and upstream server?

我使用 OpenResty® 来代理我的后端服务器。 流程是client->proxy server->backend server

问题是代码的注释:

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
        }
    }}

客户端向代理服务器发送消息,代理服务器将消息转发给后端server.The代理服务器会新建一个套接字连接后端服务器,那么如何获取代理服务器与代理服务器之间的代理服务器套接字端口和 content_by_lua_block?

中的后端服务器

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.

...

顺便说一句,proxy_pass 和 content_by_lua_block 都是内容阶段指令。 只有一个会起作用。请看这个posthttps://groups.google.com/forum/#!topic/openresty-en/DRocQpM4mVY