AWS 颁发的证书失败

时间:2021-03-08 23:35:40

标签: node.js amazon-web-services

我有 AWS 为我的域颁发的证书,并根据通知我在 register.com 上配置了它。问题是,当我用 www.example.com 打开网站时,它显示为无效证书,但当我直接用 https://example.com 打开它时,它显示为有效证书。

我使用 NodeJS 作为服务器,如何重定向以始终打开像 https://example.com 这样的域?

现在是这样工作的:

app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Headers', 'Locale, X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, Content-Encoding');
    res.setHeader('Access-Control-Expose-Headers', 'Locale');

    if ((req.headers["x-forwarded-proto"] || "").endsWith("http")) {
        res.redirect(`https://${req.headers.host}${req.url}`); 
    }    
    next();
});

我的证书

enter image description here

1 个答案:

答案 0 :(得分:1)

您必须为 www.example.comexample.com 注册 SSL 证书。仅注册一个将不起作用,因为 www.example.com 将被视为与 example.com 不同。

enter image description here

相关问题