[英]Creating SSL certificates for using with Node.js
我需要在https
協議上運行本地Express服務器。 我使用了本網站和類似的說明。 但是當我試圖在瀏覽器中打開頁面時,我得到Your connection is not private
錯誤。 當我從Developer tools
打開Security
選項卡時,我看到This site is missing a valid, trusted certificate (net::ERR_CERT_INVALID)
錯誤。 當我嘗試通過Postman發送請求時,我的服務器沒有響應,並且curl
請求返回:
curl: (60) SSL certificate problem: unable to get local issuer certificate
這是服務器代碼:
const app = require('express')();
const fs = require('fs');
const https = require('https');
const options = {
key: fs.readFileSync('./key.pem'),
cert: fs.readFileSync('./cert.pem')
};
app.get('/', (req, res) => {
res.send('hello world');
});
https
.createServer(options, app)
.listen(3000, '127.0.0.1', () => {
console.log('Run on: https://127.0.0.1:3000');
});
我用下一個命令創建了證書:
$ openssl req -nodes -sha256 -new -x509 -keyout key.pem -out cert.pem -days 365 -config req.cnf
其中req.cnf
文件具有以下內容:
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = US
ST = VA
L = SomeCity
O = MyCompany
OU = MyDivision
CN = 127.0.0.1:3000
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = IP:127.0.0.1:3000
我也嘗試使用443
端口,但不幸的是,我遇到了同樣的錯誤。 此外,我試圖打開頁面https://127.0.0.1:3000
與隱身模式 - 沒有發生 - 錯誤是相同的。
我的問題是:
您創建的是自簽名證書 ,默認情況下,沒有網絡應用程序會接受它們,因為它們無法驗證它們,因此它們會更糟糕(MITM攻擊)。
如果您只需要進行本地檢查,則可以按照此“ 獲取Chrome”接受自簽名本地主機證書
郵差錯誤可能是Chrome應用程序的等效錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.