简体   繁体   中英

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

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM