大网数据广告活动
服务器运维问答

Socket IO combined with apache ssl server

· 52CE 我爱测

I'm trying to run a NodeJS server on port 8000 along with my Apache server which has a ssl certificate. I'm using virtual hosts and proxypass to link from my apache website through the /node path to my NodeJS server. The problem …

问题原文

原帖链接 · Crecket · CC BY-SA 3.0

I'm trying to run a NodeJS server on port 8000 along with my Apache server which has a ssl certificate. I'm using virtual hosts and proxypass to link from my apache website through the /node path to my NodeJS server.

The problem I'm having right is that I'm able to load the pages served with the Express plugin but the polling from SocketIO connections seem to fail. I've tried a bunch of things but I just cant seem to get it to work.

If I setup my client to listen to

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

My console show something along the lines of this:

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

Also, I know how to use SSL with my NodeJS server but I assume isn't going to work since I'm also listening through port 443 with my apache server.

Anyone knows if this is even possible and/or how to set this up?

EDIT: Forgot to mention I'm running on Ubuntu 14.04 x64

已采纳解答

原帖链接 · Crecket · CC BY-SA 3.0

I've finally figured it out.

Server side I run the following code on my nodeJS app:

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

Client side I serve a page using my Apache server which simply uses the following to establish the connection.

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

I never realized you could run ssl over a port like 8000 in this way.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-12-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。