gpt4 book ai didi

node.js - Amazon Elastic 负载均衡器未填充 x-forwarded-proto header

转载 作者:搜寻专家 更新时间:2023-10-31 22:27:26 24 4
gpt4 key购买 nike

我试图将所有 http 请求强制转换为 https 请求,但我面临的问题是弹性负载均衡器未在请求中填充 x-forwarded-proto header 。

这是我正在使用的代码,因此导致了重定向循环。我该如何解决这个问题?

app.use (function (req, res, next) {
console.log('Request headers = ' + JSON.stringify(req.headers));
console.log('Request protocol = ' + JSON.stringify(req.protocol));
var schema = (req.headers['x-forwarded-proto'] || '').toLowerCase();
if (schema === 'https') {
next();
} else {
res.redirect('https://' + req.headers.host + req.url);
}
});

最佳答案

听起来您的 ELB 监听器可能配置为 TCP 而不是 HTTP。配置为 TCP,它不会添加 X-Forwarded-Proto 或 X-Forwarded-For。

关于node.js - Amazon Elastic 负载均衡器未填充 x-forwarded-proto header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19049320/

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