如何使用节点配置ssl
How to configure ssl with node
我是新手 Angular 和 Node Stuff。
我正在尝试 运行 我的 angular 节点上的应用程序以及 https/ssl。
我使用 certbot
安装了以下文件
git clone https://github.com/certbot/certbot
cert.pem -> ../../archive/mypleaks.com/cert1.pem
chain.pem -> ../../archive/mypleaks.com/chain1.pem
fullchain.pem -> ../../archive/mypleaks.com/fullchain1.pem
privkey.pem -> ../../archive/mypleaks.com/privkey1.pem
然后我在应用程序内的 ssl 文件夹中使用以下命令将 cert.pem 转换为 key.pem 和 server.cert。
sudo openssl req -newkey rsa:2048 -new -nodes -keyout /etc/letsencrypt/live/mypleaks.com/cert.pem -out key.pem
sudo openssl x509 -req -days 365 -in key.pem -signkey /etc/letsencrypt/live/mypleaks.com/cert.pem -out server.crt
然后我按照这个article link配置了prod.js
const port = process.env.PORT || 443;
const server = require('./dist/server');
var fs = require('fs'),
https = require('https');
var options = {
key: fs.readFileSync('./ssl/key.pem'),
cert: fs.readFileSync('./ssl/server.crt')
};
var httpsServer = https.createServer(options, server.app).listen(port, () => {
console.log("Express server listening on port " + port);
});
在使用 npm run build:prod
构建项目后,当我 运行ning npm run prod
时,出现以下错误:-
> myPleaks@0.0.0 prod /Users/deraj/home/mypleaks-ui/myPleaks
> node prod.js
Using browser-only version of superagent in non-browser environment
_tls_common.js:104
c.context.setKey(options.key, options.passphrase);
^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.createSecureContext (_tls_common.js:104:17)
at Server (_tls_wrap.js:805:25)
at new Server (https.js:54:14)
at Object.createServer (https.js:76:10)
at Object.<anonymous> (/Users/deraj/home/mypleaks-ui/myPleaks/prod.js:10:25)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myPleaks@0.0.0 prod: `node prod.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myPleaks@0.0.0 prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/deraj/.npm/_logs/2018-10-07T19_49_16_195Z-debug.log
我很努力地尝试了,但无法修复错误。请给我一些解决方案。?
您的 pem 文件似乎无效。
我从来没有那样创建过,前一段时间我正在做你正在做的事情,我创建了 pem 文件如下:
您只需选择您的 "software" 和 "system" 并按照教程进行操作。
我是新手 Angular 和 Node Stuff。 我正在尝试 运行 我的 angular 节点上的应用程序以及 https/ssl。 我使用 certbot
安装了以下文件git clone https://github.com/certbot/certbot
cert.pem -> ../../archive/mypleaks.com/cert1.pem
chain.pem -> ../../archive/mypleaks.com/chain1.pem
fullchain.pem -> ../../archive/mypleaks.com/fullchain1.pem
privkey.pem -> ../../archive/mypleaks.com/privkey1.pem
然后我在应用程序内的 ssl 文件夹中使用以下命令将 cert.pem 转换为 key.pem 和 server.cert。
sudo openssl req -newkey rsa:2048 -new -nodes -keyout /etc/letsencrypt/live/mypleaks.com/cert.pem -out key.pem
sudo openssl x509 -req -days 365 -in key.pem -signkey /etc/letsencrypt/live/mypleaks.com/cert.pem -out server.crt
然后我按照这个article link配置了prod.js
const port = process.env.PORT || 443;
const server = require('./dist/server');
var fs = require('fs'),
https = require('https');
var options = {
key: fs.readFileSync('./ssl/key.pem'),
cert: fs.readFileSync('./ssl/server.crt')
};
var httpsServer = https.createServer(options, server.app).listen(port, () => {
console.log("Express server listening on port " + port);
});
在使用 npm run build:prod
构建项目后,当我 运行ning npm run prod
时,出现以下错误:-
> myPleaks@0.0.0 prod /Users/deraj/home/mypleaks-ui/myPleaks
> node prod.js
Using browser-only version of superagent in non-browser environment
_tls_common.js:104
c.context.setKey(options.key, options.passphrase);
^
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.createSecureContext (_tls_common.js:104:17)
at Server (_tls_wrap.js:805:25)
at new Server (https.js:54:14)
at Object.createServer (https.js:76:10)
at Object.<anonymous> (/Users/deraj/home/mypleaks-ui/myPleaks/prod.js:10:25)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myPleaks@0.0.0 prod: `node prod.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myPleaks@0.0.0 prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/deraj/.npm/_logs/2018-10-07T19_49_16_195Z-debug.log
我很努力地尝试了,但无法修复错误。请给我一些解决方案。?
您的 pem 文件似乎无效。
我从来没有那样创建过,前一段时间我正在做你正在做的事情,我创建了 pem 文件如下:
您只需选择您的 "software" 和 "system" 并按照教程进行操作。