问题描述
我正在尝试将SSL添加到示例WebRTC视频聊天应用程序的HTTPserver。 我已经尝试将SSL添加到我的Lighttpd中,并且仅添加到代理中,但是Socket.IO连接由于混合了https / nonhttps内容而无法正常工作。我想为此需要一个独立的节点https服务器应用程序。 我是Node的新手,需要帮助...
这是我的应用程序:
index.ts
BearerTokenHandler
server.ts
IdentityModel
解决方法
使用https
库而不是http
:
const https = require('https');
const fs = require('fs');
const privateKey = fs.readFileSync('./localhost.key','utf8');
const certificate = fs.readFileSync('./localhost.crt','utf8');
const credentials = {
key: privateKey,cert: certificate,};
const httpsServer = https.createServer(credentials,this.app);
可以这样生成自签名证书:
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
有关更多信息,请参见https://letsencrypt.org/docs/certificates-for-localhost/#making-and-trusting-your-own-certificates。