我们应该在哪里放置 SSL 的 key.pem 和 certificate.pem 文件?

where should we put key.pem and certificate.pem file for SSL?

我已经为 SSL 编写了以下代码,但出现错误“SSL_ERROR_RX_RECORD_TOO_LONG”,请告诉我将 key.pem 和 certificate.pem 放在我的本地位置以摆脱错误

if (settings.local) {
    https.createServer({
            key: fs.readFileSync('key.pem'),
            cert: fs.readFileSync('certificate.pem')

    }, app).listen(https_port);
    console.log("server starting on https://localhost:" + https_port);

这对我来说更像是一个 TLS 问题。别担心,您的代码可以读取证书,否则会抛出另一个错误。

对于你的第一个问题,我通常把它们放在 certs/{cert.pem, key.pem}

然后第二个:

您可能试图将 non-SSL 数据发送到不支持 SSL 的服务器。尝试通过 http 而不是 https 访问您的站点。 http://localhost:port 而不是 https://localhost:port

如果这也不起作用,我从我的项目中获得了一些示例代码

import https from "http2";
import fs from "fs";
import path from "path";
import url from "url";

const options:https.SecureServerOptions = {
    key: fs.readFileSync(path.join(__dirname, "certs/key.pem")),
    cert: fs.readFileSync(path.join(__dirname, "certs/cert.pem")),
    minVersion: "TLSv1.3" //Try 1.3 or 1.2
};

const server = https.createSecureServer(options, async (req, res) => {})
.listen(https_port).on("listening", () => {
console.log(`Server listening on port ${process.env.PORT || 3000}`);