节点脚本不会通过https运行

时间:2014-04-08 14:31:04

标签: javascript node.js ssl

我遇到问题,我的网站现在有SSL证书,但现在我的节点脚本没有运行。

的node.js

var cs = require('./chatServer.js');
var ns = require('./notificationServer.js');
ns.start();
cs.start();

notificationServer.js

var io = require('socket.io').listen(3002,{log:false});
var sys = require('util');
var moment = require('moment');
function notificationStart(){
    io.sockets.on('connection', function(socket) {
        // my code
    });
}
exports.start=notificationStart;

chatServer.js

var io = require('socket.io').listen(3003,{log:false});
var sys = require('util');
var DBWrapper = require('node-dbi').DBWrapper; 
var DBExpr = require('node-dbi').DBExpr;
function chatStart()
{
    io.sockets.on('connection', function (socket) 
    {
        // my code
    });
}
exports.start = chatStart;

的index.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="https://mydomain.com:3003/socket.io/socket.io.js"></script>
<script type="text/javascript" src="web/controllers/js/myChat.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var mychat = new myChat();
        mychat.init('name','channel', 't', true);
    });
</script>

myChat.js

function myChat(){
    var _this = this;
    this.chatServer;
    this.init = function(user, room, type, announce, publicChannel,window){
        _this.chatServer = io.connect('https://mydomain.com:3003');
        _this.chatServer.on('connect',function(){
            _this.chatServer.emit('adduser', user, room, type);
        });
    };
}

在终端:

  

节点/my/path/node.js

当网站是HTTP时,node.js工作,但现在不能使用HTTPS 有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您的socket.io配置为使用http协议,而不是https协议。我很确定你是否改变了(在myChat.js中):

io.connect('https://mydomain.com:3003');

by:

io.connect('http://mydomain.com:3003');

它会起作用。

(检查您的端口)

要使用HTTPS协议配置socket.io,请转到here

我在Google上发现:http://chrislarson.me/blog/ssl-nodejs-express-and-socketio