linux express配置ssl证书,开启https访问
1.下载ssl证书的Nginx版本,在项目根目录新建https空文件夹,把crt文件和key文件复制到https文件夹中;
2.安装依赖:npm i fs http https
3.修改www文件的内容:
var https = require('https');
var fs = require('fs');
var path = require('path');
var privateCrt = fs.readFileSync(path.join(process.cwd(), 'https/xxxx.crt'), 'utf8');
var privateKey = fs.readFileSync(path.join(process.cwd(), 'https/xxxx.key'), 'utf8');
const HTTPS_OPTOIN = {
key: privateKey,
cert: privateCrt
};
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '8000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = https.createServer(HTTPS_OPTOIN,app);