Route requests to an http server listening on a unix socket

654 views
Skip to first unread message

axeljohnsson

unread,
Nov 22, 2010, 3:39:19 PM11/22/10
to nodejs
Hi,

I want to route requests that comes in to a public node http server,
to another node http server listening on a unix socket.

I know it's possible with nginx but I want to do it with node js.

Can I use http.createClient but with a socket path instead of port and
host?
Or is it better to use the net module in some way?

I have made som research but I can't figure it out.

Tim Caswell

unread,
Nov 22, 2010, 5:08:13 PM11/22/10
to nod...@googlegroups.com
What nginx does is proxy each and every request to a backend server.
You can do this in node, but it's non-trivial to get it right. I
believe there are some node modules for this already. Look for "http
reverse-proxy"

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

Axel Johnsson

unread,
Nov 22, 2010, 5:40:14 PM11/22/10
to nod...@googlegroups.com
Yes, for example https://github.com/nodejitsu/node-http-proxy do what I want.
But only with ports and not with unix sockets. So my problem remains, how to send http requests to a server listening on a socket.

Do you know any project/code where I can look?

Thanks for your answer. =)

Tim Caswell

unread,
Nov 22, 2010, 6:01:19 PM11/22/10
to nod...@googlegroups.com
It should be trivial to connect to a unix socket instead of a ip/port.
As far as I know you simply put the path to the socket in instead of
the IP and port when connecting or listening.

Axel Johnsson

unread,
Nov 23, 2010, 2:13:00 PM11/23/10
to nod...@googlegroups.com
I did not try to put the path to the socket in the createClient function before I post here. I thought it would not work, but it did a little bit. I'm able to send the request, but not to send the response back from the server to the proxy.

I will work on a possible solution. Any tips are welcome. =)
Reply all
Reply to author
Forward
0 new messages