我已经有一个使用nodeJs语言在HTTP上运行的应用程序。我想开始改用HTTPS。我当前的实现是:
var fs = require('fs');
var https = require('https');
var certificate = fs.readFileSync('filename.pfx', 'utf8');
var credentials = {key: 'password', pfx: certificate};
dotenv.config({ silent: true });
const app = express();
app.use(/^\/(?!ready).*/);
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(PORT, logger.info(`Server listening on port: ${PORT}`));
我面临的错误是:
_tls_common.js:144
c.context.setKey(key, passphrase);
^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.createSecureContext (_tls_common.js:144:17)
at Server (_tls_wrap.js:867:27)
at new Server (https.js:62:14)
有人可以帮忙吗?
答案 0 :(得分:0)
已解决:
var options = {
pfx: fs.readFileSync([filename]),
passphrase: [password]
};
[...app definition...]
var httpsServer = https.createServer(options, app);
httpsServer.listen(PORT, logger.info(`Server listening on port: ${PORT}`));