Node.js - 具有WebSocket代理和SSL支持的优秀WebServer?

Van*_*ing 4 proxy webserver websocket node.js

我真的很喜欢node.js但是当你想要运行多个websocket服务器并使它们都可以通过端口80访问时,它真的很复杂.

我目前正在运行nginx,但由于nginx不支持http 1.1,因此根据url代理传入的websocket连接到不同的websocket服务器是不可能的.

我曾尝试实现一个自己拥有该功能的网络服务器,但在标题传递等方面它确实很复杂.另一件事是SSL支持.支持它并不容易.

那么,有没有人知道做我提到的事情的好方法?

谢谢你的帮助!

sch*_*rmu 8

我使用nodejitsu的node-http-proxy获得了很好的结果.如他们的自述文件所述,它们似乎支持WebSockets.

WebSockets的示例(取自他们的GitHub自述文件):

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
  });
});
Run Code Online (Sandbox Code Playgroud)

它的生产用量应该没问题,因为它用于nodejitsu.com.要将代理应用程序作为守护程序运行,请考虑永久使用.