Node.js + Express.js + Socket.io on port 443 (HTTPS TLS/SSL)

余生颓废 提交于 2019-12-08 01:26:17

问题


I have an app with Node.js, Express.js, and Socket.io that runs fine using ANY port except 443. The server is meant to only operate over HTTPS port 443 and likewise, the websocket should be encrypted as well.

CODE THAT WORKS

var fs = require('fs');
var https = require('https');
var express = require('express');
var socket = require('socket.io');
var sslOptions = {
    key: fs.readFileSync(__dirname + '/../ssl/server.key,
    cert: fs.readFileSync(__dirname + '/../ssl/server.pem,
    ciphers: 'ECDHE-RSA-AES256-SHA:AES256-SHA:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM',
    honorCipherOrder: true
};

var app = express();
var server = https.createServer(sslOptions, app);
var io = socket.listen(server, {
    "log level" : 3,
    "match origin protocol" : true,
    "transports" : ['websocket']
});
server.listen(8443);

When I change the port (last line) to 443, the Node server crashes right away with an error:

warn: error raised: Error: listen EADDRINUSE

回答1:


Apparently you've already got a server listening on that port on your machine. Is is possible that you started this server elsewhere and it's still running?




回答2:


It means that the port is in use, you can check using : sudo netstat -tapen | grep ":443". If you use Apache, Ngnix or other server it is likely to be it.



来源:https://stackoverflow.com/questions/22725717/node-js-express-js-socket-io-on-port-443-https-tls-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!