I ended up using lua's "content by lua" capabilities instead of nginx_tcp_proxy. I'd use lua to make the tcp call and pass the content back through nginx.
Nginx HTTPS to TCP proxy prepending data
题
I have nginx_tcp_proxy_module set up to proxy xml post data from an https connection to a tcp socket for a third party service that I don't have access to.
The setup is working fine, except that it seems that some data is pre-pended to the original data before being sent upstream, which results in some REQUEST FAILURE errors in the response from the tcp service. There are always 6 FAILURE lines before the correct data is returned, which makes me think that some sort of header or content length is being added.
Is there a way to prevent nginx_tcp_proxy_module from adding anything to the headers?
I'm not able to see the data that's actually being sent upstream (Is there a way to get nginx_tcp_proxy_module to log the data that it receives and the data that it sends upstream?)
I'm using requests on the client side:
[requests] <---> [nginx https to tcp proxy] <----> [upstream tcp service]
My requests call is something like this:
response = requests.post("https://nginx-server.com:port", data="<xml-data-string>", verify="/path/to/certificiate")
My nginx config:
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;
}
}
And lastly, the response is something like
<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.
解决方案