mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Simple forward proxy

Open nevson opened this issue 11 years ago • 2 comments

Hi, I want to map several services running on different ports onto one central URI e.g. https://myserver.int ~~which is public accessible. Other ports will be blocked for the outside so that these other "hidden" services are only locally accessible~~. I.e. I want to achieve following mapping:

https://myserver.int/service1/ -> tcp://localhost:8081/
https://myserver.int/service2/ -> tcp://localhost:8082/
...

My initial thought was to write a proxy which forwards the requests to the servers depending on the URI. Is this the correct approach to achieve this or is there a better way or am I understanding something completely wrong?

I got an initial proxy server running and the requests e.g. https://myserver.int/service1/ are getting correctly forwarded to tcp://localhost:8081/ but my problem is that there are no persistent connections which is especially critical for SSL. Currently each XHR request creates a new connection even though the header Connection: keep-alive is set. Is this not possible or am I doing something wrong?

Here you can find a little Gist showing my proxy https://gist.github.com/nevson/25f096dd64e4571077e8

connection_setup

Any help would be appreciated!

Edit: Sorry I've to reword my question. In fact I want to figure out a way how I can bind a service/server to a stable URL e.g. https://myserver.int/service1/ so that I can easily exchange the services.

https://myserver.int/service1/ -> https://myserver.int:8081
change to
https://myserver.int/service1/ -> https://myserver1234.int:8081

After thinking more about the proxy idea I'm not really sure if that is the best solution for me as all traffic would need to get tunneled over it. What other alternatives exists? Would be a solution like mod_rewrite be more suitable and if so, how can I do such kind of URL rewrite with Mongoose?

nevson avatar Jul 23 '15 13:07 nevson

Are you trying to make something like https://github.com/cesanta/fossa/tree/master/apps/load_balancer ?

cpq avatar Jul 28 '15 05:07 cpq

based on your description, what you need is indeed a proxy, bu Mongoose isn't one. load_balancer example that Sergey mentioned is close to what you need but there are currently no plans to add that functionality to mongoose.c

rojer avatar May 15 '16 13:05 rojer