获取OpenSSL
Unbuntu:sudo apt-get install openssl
Other Linux:http://www.openssl.org/source
Windows:
Windows环境变量OPENSSL_CONF
SET OPENSSL_CONF=openssl.cnf
生成私钥和公共证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout xxx.pem -out xxx.crt
免费证书生成网站
在Express中启用https
var https = require('https');
var app = require('express')();
var fs = require('fs');
app.set('port', process.env.PORT || 3000);
var options = {
key: fs.readFileSync(__dirname + '/ssl/localhost.key'),
cert: fs.readFileSync(__dirname + '/ssl/localhost.cert')
};
https.createServer(options, app).listen(app.get('port'), function () {
console.log('Express started in ' + app.get('env') +
' mode on port ' + app.get('port') + '.');
});