如何通过socket.io设置一个安全的websocket(ssl / wss)?

一切正常,没有ssl连接。

在我设置之后回复的回复:
socket.io-1.4.5.js:1
GET https://domain.com:3000/socket.io/?EIO=3&transport=polling&t=LILwU3l net::ERR_INSECURE_RESPONSE


服务器

node.js v.6.1

的package.json

 { //..., "dependencies": { "socket.io": "1.4.5" } } 

server.js

看看如何声明socket.io解决了如何创build一个服务器: https : //github.com/socketio/socket.io/blob/master/lib/index.js#L212

 const fs = require('fs'), https = require('https').createServer( { // certificate by godaddy (G2) key : fs.readFileSync('/etc/ssl/private/domain.key'), cert: fs.readFileSync('/etc/ssl/certs/domain.crt') }, (req, res) => { res.writeHead(404); res.end(); }).listen(3000), io = require('socket.io')(https); io.on('connection', (socket) => {console.log('CONNECTED');}); 

客户

 require.config( { shim: { 'socketio': { exports: 'io' } }, paths: { socketio: 'https://cdn.socket.io/socket.io-1.4.5' } }); define(['socketio'], function(io) { var socket = io.connect('https://domain.com:3000'); }); 

SSLvalidation

 $ openssl s_client -CApath /etc/ssl/certs/ -connect domain.com:3000 -showcerts ... Verify return code: 0 (ok) 

       

网上收集的解决方案 "如何通过socket.io设置一个安全的websocket(ssl / wss)?"