Nginx HTTPS到TCP代理前置数据

时间:2014-05-13 07:38:02

标签: sockets nginx tcp proxy

我已将nginx_tcp_proxy_module设置为将来自https连接的xml发布数据代理到tcp套接字,以用于我无权访问的第三方服务。

设置工作正常,除了在上游发送之前似乎某些数据预先设置为原始数据,这导致tcp服务的响应中出现一些REQUEST FAILURE错误。在返回正确的数据之前总是有6条FAILURE行,这使我认为正在添加某种标题或内容长度。

有没有办法阻止nginx_tcp_proxy_module向标题添加任何内容?

我无法看到实际上传的数据(有没有办法让nginx_tcp_proxy_module记录它收到的数据以及它向上游发送的数据?)

我在客户端使用请求:

[requests] <---> [nginx https to tcp proxy] <----> [upstream tcp service]

我的请求电话是这样的:

response = requests.post("https://nginx-server.com:port", data="<xml-data-string>", verify="/path/to/certificiate")

我的nginx配置:

tcp {   
    access_log  /var/log/nginx/tcp_access.log;

    upstream tcpservice {
            server upstream-server:port;
            check interval=3000 rise=2 fall=5 timeout=1000;
    }

    server {
            listen port;
            server_name nginx-server.com;

            so_keepalive on;
            tcp_nodelay on;

            ssl on;
            ssl_certificate /path/to/cert;
            ssl_certificate_key /path/to/key;
            proxy_pass tcpservice;
    }
}

最后,响应类似于

<REQUEST ERROR>
<REQUEST ERROR>
<REQUEST ERROR>
<REQUEST ERROR>
<REQUEST ERROR>
<REQUEST ERROR>
<CORRECT DATA> <--- Only this should show if the request is fine, as tested by passing the request string directly down the tcp socket.

1 个答案:

答案 0 :(得分:0)

我最终使用lua&#34;内容由lua&#34;功能而不是nginx_tcp_proxy。我使用lua进行tcp调用并通过nginx传回内容。