I really love node.js but it´s really complicating when you want to run multiple websocket servers and make them all accessible over port 80.
I'm currently running nginx, but proxying incoming websocket connections to the different websocket servers depending on the url is not possible because nginx does not support http 1.1.
I´ve tried to implement a webserver that has the functionality on my own, but it is really complicated when it comes to header passing etc. Another thing is SSL support. It´s not easy to support it.
So, does anyone know a good solution to do the things i mentioned?
Thanks for any help!
I had good results using node-http-proxy by nodejitsu. As stated in their readme, they seem to support WebSockets.
Example for WebSockets (taken from their GitHub readme):
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create an instance of node-http-proxy
//
var proxy = new httpProxy.HttpProxy();
var server = http.createServer(function (req, res) {
//
// Proxy normal HTTP requests
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8000
})
});
server.on('upgrade', function(req, socket, head) {
//
// Proxy websocket requests too
//
proxy.proxyWebSocketRequest(req, socket, head, {
host: 'localhost',
port: 8000
});
});
It's production usage should be no problem since it is used for nodejitsu.com. To run the proxy app as a daemon, consider using forever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With