4

We have a service which listens on a TCP socket for a non-HTTP request. We'd like to put an HTTP reverse proxy in front of it such that the body of the HTTP request is forwarded as the entire request to the TCP socket.

We've looked at doing this with nginx, but while it can easily reverse proxy TCP -> TCP & HTTP -> HTTP, we haven't come across any way to do HTTP -> TCP. Is there any "out-of-the-box" reverse proxy software that will do this for us, or do we need to build something custom?

btucker
  • 181
  • 1
  • 4
  • Can you give more details about why you would want to do this? It almost seems like you want a [CONNECT proxy](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling), but this usually requires configuration on the client. – Zoredache Apr 05 '17 at 18:53
  • @Zoredache Sure, our use case is that we want to enable browsers to make ajax requests that ultimately hit this TCP socket & then return the response for a POC. We're trying to avoid introducing a full web service sitting in front of the TCP service just to keep the stack simpler – btucker Apr 05 '17 at 21:15
  • I'm curious whether you found the solution, because I need it too. Client sends http/json request to nginx, and all we need is to pass json body as-is ("unhttpise" it) to internal tcp service. And then httpise it's json answer back to the client. I think we can write lua handler to do that, but it seems like overkill, since all session/header/etc processing can be done in nginx.conf. – user3125367 Sep 07 '17 at 05:54

2 Answers2

1

You may try fcgi-function

It depends nginx to enable fastcgi pass to the service, then you could do whatever you want. Read the Readme for more details, you can start from scratch.

Oktaheta
  • 111
  • 1
0

It's about 10 lines of PHP or python code. Maybe a couple more in lua.

There's probably a github gist somewhere to do it but it'll take longer to find it than to write from scratch.

If you want something with lots of bells and whistles which is well maintained, then use websockify - but note that the client needs to use websockets - not just HTTP.

symcbean
  • 21,009
  • 1
  • 31
  • 52