如何使用node.js和express.js设置SSL

How Do I Setup SSL with node.js and express.js?

本文关键字:js 设置 SSL express node 何使用      更新时间:2024-02-20

我正在尝试将我的应用程序配置为在HTTPS模式下运行。我认为我的配置是正确的,但页面根本没有加载。

在我的SSL文件夹中,我有:

credentials.js
my-ca.pem
my-cert.pem
my.pem

内部凭证,我有:

var fs = require('fs');
var credentials = {
    key: fs.readFileSync(__dirname + '/my.pem', 'utf8'),
    cert: fs.readFileSync(__dirname + '/my-cert.pem', 'utf8'),
    ca: fs.readFileSync(__dirname +  '/my-ca.pem', 'utf8'),
    passphrase: 'myphrase'
};
module.exports = credentials;

然后,在我的bin/www文件中,我有:

var app = require('../app');
var https = require('https');
var credentials = require('../ssl/credentials');
https.createServer(credentials, app).listen(app.get('port'), app.get('ip'), function() {
  console.log('Running on port ' + app.get('port') + ' in ' + app.get('env') + ' mode.');
});

这应该奏效,不是吗?

您是否专门转到https://localhost:3000