Node.js - 带有 WebSocket 代理的优秀 WebServerSSL 支持? [英] Node.js - Good WebServer with WebSocket-proxying & SSL support?

查看:56
本文介绍了Node.js - 带有 WebSocket 代理的优秀 WebServerSSL 支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我目前正在运行 nginx,但无法根据 url 将传入的 websocket 连接代理到不同的 websocket 服务器,因为 nginx 不支持 http 1.1.

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.

我已经尝试实现一个具有我自己功能的网络服务器,但是当涉及到标头传递等时它真的很复杂.另一件事是 SSL 支持.支持它并不容易.

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?

感谢您的帮助!

推荐答案

我使用 node 取得了不错的效果-http-proxy 由 nodejitsu 提供.正如他们的自述文件所述,他们似乎支持 WebSockets.

I had good results using node-http-proxy by nodejitsu. As stated in their readme, they seem to support WebSockets.

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

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
  });
});

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

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.

这篇关于Node.js - 带有 WebSocket 代理的优秀 WebServerSSL 支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆