node.js socket支持https 配置修改
nodejs 需要有 https模块和 fs模块(文件系统)
var socketio = require('socket.io'),
fs = require('fs'), //引入fs模块
https = require('https'), // 引入http模块改为 引入https 注意相应位置修改
domain = require('domain'),
redis = require('redis'),
redisio = require('socket.io-redis'),
request = require('request'),
config = require('./config.js');
var d = domain.create();
d.on("error", function(err) {
console.log(err);
});
//通过文件系统 引入key文件
var options = {
key: fs.readFileSync('../nginx/conf/ssl/xianggang.yunbaozhibo.com.key'),
cert: fs.readFileSync('../nginx/conf/ssl/xianggang.yunbaozhibo.com.crt')
};
var numscount=0;// 在线人数统计
var sockets = {};
var chat_history={};
var chat_interval={};
var field=[];
// redis 链接
var clientRedis = redis.createClient(config['REDISPORT'],config['REDISHOST']);
clientRedis.auth(config['REDISPASS']);
//创建服务时使用参数
var server = https.createServer(options,function(req, res) {
res.writeHead(200, {
'Content-type': 'text/html;charset=utf-8'
});
//res.write("人数: " + numscount );
res.end();
}).listen(19968, function() {
//console.log('服务开启19967');
});