我尝试在我的nodejs服务器上运行https,如下所示:
var http = require('http');
var https = require('https');
var fs = require('fs');
var express = require('express');
var privateKey = fs.readFileSync('server.key', 'utf8');
var certificate = fs.readFileSync('server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var app = express();
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(8080, ()=> {
console.log('Server started and listening on port 8080...')
});
httpsServer.listen(8443, ()=>{
console.log('Server started and listening on port 8443...')
});
字符串
当我运行服务器时,只有http url在工作,https超时了。你知道为什么会发生这种情况吗?
我习惯使用cpanel,所以我已经在那里设置了ssl证书,但是当涉及到node时,我碰壁了。
2条答案
按热度按时间x8goxv8g1#
看起来你的ssl文件有问题,你需要给予证书文件和私钥,同时创建https服务器像这样:
字符串
希望对你有帮助。
goqiplq22#
问题是端口没有转发。