Skip to content Skip to sidebar Skip to footer

Node.js Http-proxy Drops Websocket Requests

Okay, I've spent over a week trying to figure this out to no avail, so if anyone has a clue, you are a hero. This isn't going to be an easy question to answer, unless I am being a

Solution 1:

In general I don't think node is not the most used option as a proxy server, I, for one use nginx as a frontend server for node and it's a really great combination. Here are some instructions to install and use the nginx sticky sessions module.

It's a lightweight frontend server with json like configuration, solid and very well tested.

nginx is also a lot faster if you want to serve static pages, css. It's ideal to configure your caching headers, redirect traffic to multiple servers depending on domain, sticky sessions, compress css and javascript, etc.

You could also consider a pure load balancing open source solution like HAProxy. In any case I don't believe node is the best tool for this, it's better to use it to implement your backend only and put something like nginx in front of it to handle the usual frontend server tasks.

Solution 2:

I agree with hexacyanide. To me it would make the most sense to queue workers through a service like redis or some kind of Message Query system. Workers would be queued through Redis Pub/Sub functionality by web nodes(which are proxied). Workers would callback upon error, finish, or stream data in realtime with a 'data' event. Maybe check out the library kue. You could also roll your own similar library. RabbitMQ is another system for similar purpose.

I get using socket.io if you're already using that technology, but you need to use tools for their intended purpose. Redis or a MQ system would make the most sense, and pair great with websockets(socket.io) to create realtime, insightful applications.

Session Affinity(sticky sessions) is supported through Elastic LoadBalancer for aws, this supports webSockets. A PaaS provider(Modulus) does this exactly. Theres also satalite which provides sticky sessions for node-http-proxy, however I have no idea if it supports webSockets.

Solution 3:

I've been looking into something very similar to this myself, with the intent of generating (and destroying) Node.js cluster nodes on the fly.

Disclaimer: I'd still not recommend doing this with Node; nginx is more stable for the sort of design architecture that you're looking for, or even more so, HAProxy (very mature, and easily supports sticky-session proxying). As @tsturzl indicates, there is satellite, but given the low volume of downloads, I'd tread carefully (at least in a production environment).

That said, since you appear to have everything already set up with Node, rebuilding and re-architecting may be more work than it's worth. Therefore, to install the caronte branch with NPM:

  1. Remove your previous http-node-proxy Master installation with npm uninstall node-proxy and/or sudo npm -d uninstall node-proxy

  2. Download the caronte branch .zip and extract it.

  3. Run npm -g install /path/to/node-http-proxy-caronte
  4. In my case, the install linkage was broken, so I had to run sudo npm link http-proxy

I've got it up and running using their basic proxy example -- whether or not this resolves your dropped sessions issue or not, only you will know.

Post a Comment for "Node.js Http-proxy Drops Websocket Requests"