我正在使用 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。这些是我得到的错误:
问题可能是证书是自签名的吗?我的代码如下
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);
});
这段代码对我有用!
在app.json中
把这个放进去
{ “博览会”: {
"plugins": [
["expo-build-properties", {
"android": {
"usesCleartextTraffic": true
},
"ios": {
}
}]
} }