gpt4 book ai didi

node.js - Node https ssl 你的连接不是私有(private)错误

转载 作者:行者123 更新时间:2023-12-03 12:17:57 25 4
gpt4 key购买 nike

我最近购买了一个 ssl 证书,当我访问我的网站时,我遇到了 google chrome 的问题,它显示“您的连接不是私有(private)的 NET::ERR_CERT_AUTHORITY_INVALID”,这就是我正在做的事情:

const express = require("express");
const https = require('https');
const helmet = require("helmet");
const cors = require("cors");
const fs = require("fs");
const path = require("path");
const app = express();
const config = require("./config");
const passport = require("passport");
const credentials = { key: fs.readFileSync('ssl/site.key', 'utf-8'), cert: fs.readFileSync('ssl/site.crt', 'utf-8') + fs.readFileSync('ssl/site.ca-bundle', 'utf-8') };

app.use(helmet());
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(
require("express-session")({
secret: require("./config.json").app.secretKey,
resave: false,
saveUninitialized: true,
cookie: {
secure: false,
maxAge: 60 * 60 * 1000 * 24 * 365,
},
})
);

app.use(passport.initialize());
app.use(passport.session());
passport.use(require("./service/passport"));

app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "views")));

app.use("/", require("./api/views"));
app.use("/auth", require("./api/auth"));
app.use("/answer", require("./api/answer"));
app.use("/user", require("./api/views/user.view"));
app.use("/courses", require("./api/views/courses.view"));
app.use("/question", require("./api/views/question.view"));
app.use("/answer", require("./api/views/answer.view"));

app.use("/api/user", require("./api/user"));
app.use("/api/course", require("./api/course"));
app.use("/api/feedback", require("./api/feedback"));
app.use("/api/help", require("./api/help"));
app.use("/api/questions", require("./api/question"));

var httpsServer = https.createServer(credentials, app);

httpsServer.listen(config.app.port);

console.log(credentials);
//app.listen(config.app.port);
我看到很多人有同样的问题,我该怎么办?

最佳答案

显然需要几天时间才能将认证标记为安全,这是最后的代码:

const express = require("express");
const https = require('https');
const helmet = require("helmet");
const cors = require("cors");
const fs = require("fs");
const path = require("path");
const app = express();
const config = require("./config");
const passport = require("passport");
const credentials = { key: fs.readFileSync('ssl/site.key', 'utf-8'), cert: fs.readFileSync('ssl/site.crt', 'utf-8'), ca: fs.readFileSync('ssl/site.ca-bundle', 'utf-8') };

app.use(helmet());
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(
require("express-session")({
secret: require("./config.json").app.secretKey,
resave: false,
saveUninitialized: true,
cookie: {
secure: false,
maxAge: 60 * 60 * 1000 * 24 * 365,
},
})
);

app.use(passport.initialize());
app.use(passport.session());
passport.use(require("./service/passport"));

app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "views")));

app.use('/', require('./api/home'));
app.use("/auth", require("./api/auth"));
app.use("/answer", require("./api/answer"));
app.use('/material', require('./api/material'));
app.use("/user", require("./api/user"));
app.use("/courses", require("./api/course"));
app.use('/feedback', require('./api/feedback'))
app.use("/question", require("./api/question"));
app.use("/answer", require("./api/answer"));

var httpsServer = https.createServer(credentials, app);

httpsServer.listen(config.app.port);
我还使用了通过 openssl 生成的证书,而不是我从网站收到的证书。

关于node.js - Node https ssl 你的连接不是私有(private)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62892222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com