提问人:M4rw 提问时间:11/16/2023 更新时间:11/16/2023 访问量:23
无法访问 Express JS https api
Express JS https api can't be reached
问:
我正在使用 Express js 将 node.js api 从 http 更新为 https。它托管在 AWS 上,可通过其 IP 地址(而不是 Web 域)进行访问。
我遵循了 Express 文档,并使用sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./selfsigned.key -out selfsigned.cert
但是,我的应用程序无法使用 https 访问服务器,而它使用 http。这些是我得到的错误:
- 应用程序响应:需要证书
- 邮递员响应:连接被拒绝
- Powershell 响应:Invoke-WebRequest:基础连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。
问题可能出在证书是自签名的吗?我的代码在下面
let fs = require("fs");
let https = require('https');
const crypto = require('crypto')
let express = require('express');
let expressRateLimit = require("express-rate-limit");
let mysql = require('mysql');
let bodyParser = require('body-parser');
let winston = require('winston');
require('winston-daily-rotate-file');
let key = fs.readFileSync('sslcert/selfsigned.key');
let cert = fs.readFileSync('sslcert/selfsigned.crt');
let credentials = {key: key, cert: cert};
let app = express();
app.set('trust proxy', '127.0.0.1');
app.use(bodyParser.urlencoded({extended: true}));
//App config
let httpsServer = https.createServer(credentials, app);
let httpsPort = 443;
httpsServer.listen(httpsPort, function() {
console.log("Started codeRedeem https REST API on port " + httpsPort);
});
答: 暂无答案
评论