Socket IO与apache ssl服务器结合

Socket IO与apache ssl服务器结合

我正在尝试在端口 8000 上运行 NodeJS 服务器以及具有 SSL 证书的 Apache 服务器。我使用虚拟主机和 proxypass 通过 /node 路径从我的 apache 网站链接到我的 NodeJS 服务器。

我遇到的问题是,我能够加载 Express 插件提供的页面,但 SocketIO 连接的轮询似乎失败了。我尝试了很多方法,但似乎就是无法让它工作。

如果我设置我的客户端来听

var socket = io.connect('example.com:8000', {secure: false});

我的控制台显示了类似这样的内容:

socket.io-1.3.7.js:2 GET https://example.com:8000/socket.io/?EIO=3&transport=polling&t=1451044647116-0 net::ERR_CONNECTION_CLOSED

另外,我知道如何在我的 NodeJS 服务器上使用 SSL,但我认为这不会起作用,因为我也通过我的 apache 服务器监听端口 443。

有人知道这是否可能以及/或如何设置吗?

编辑:忘了说我在 Ubuntu 14.04 x64 上运行

答案1

我终于明白了。

服务器端我在 nodeJS 应用程序上运行以下代码:

var options = {
    key: fs.readFileSync('/home/certificates.key'),
    cert: fs.readFileSync('/home/certificates.crt'),
    requestCert: true
};
var server = require('https').createServer(options, app);
var io = require('socket.io').listen(server);
server.listen(8000);
console.log('Server started at port: 8000');

客户端我使用我的 Apache 服务器提供一个页面,它仅使用以下内容来建立连接。

var socket = io.connect('example.com:8000', {secure: true});

我从来没有意识到你可以以这种方式在 8000 这样的端口上运行 ssl。

相关内容