- Mastering Node.js(Second Edition)
- Sandro Pasquali Kevin Faaborg
- 185字
- 2021-07-02 19:28:49
Creating a self-signed certificate for development
In order to support SSL connections, a server will need a properly signed certificate. While developing, it is much easier to simply create a self-signed certificate, which will allow you to use Node's HTTPS module.
These are the steps needed to create a certificate for development. The certificate we create won't demonstrate identity, as a certificate from a third party does, but it is all we need to use the encryption of HTTPS. From a terminal:
openssl genrsa -out server-key.pem 2048
openssl req -new -key server-key.pem -out server-csr.pem
openssl x509 -req -in server-csr.pem -signkey server-key.pem -out server-cert.pem
These keys may now be used to develop HTTPS servers. The contents of these files need simply be passed along as options to a Node server:
const https = require('https');
const fs = require('fs');
https.createServer({
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem')
}, (req, res) => {
...
}).listen(443);
Free low-assurance SSL certificates are available from http://www.startssl.com/ for cases where self-signed certificates are not ideal during development. Additionally, https://www.letsencrypt.org has started an exciting initiative toward providing free certificates for all (and a safer web).
- 物聯(lián)網(wǎng)安全:理論、實(shí)踐與創(chuàng)新
- Learning QGIS 2.0
- 信息通信網(wǎng)絡(luò)建設(shè)安全管理概要2
- NB-IoT物聯(lián)網(wǎng)技術(shù)解析與案例詳解
- Wireshark網(wǎng)絡(luò)分析就這么簡單
- 中小型局域網(wǎng)組建、管理與維護(hù)實(shí)戰(zhàn)
- 2018網(wǎng)信發(fā)展報(bào)告
- 6G新技術(shù) 新網(wǎng)絡(luò) 新通信
- Learning Windows 8 Game Development
- 大型企業(yè)微服務(wù)架構(gòu)實(shí)踐與運(yùn)營
- 云工廠:開啟中國制造云時代
- Hands-On Docker for Microservices with Python
- 網(wǎng)絡(luò)信息安全工程技術(shù)與應(yīng)用分析
- 物聯(lián)網(wǎng)技術(shù)與實(shí)踐
- Building Microservices with Spring