我正在使用以下命令将所有http请求重定向到https请求。在node.js中使用EBS和ELB环境将http转发到https
我可以从日志中看到标题'x-forwarded-proto'永远不会被填充并且是未定义的。
app.get('*', function(req, res, next) {
//http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#x-forwarded-proto
if (req.headers['x-forwarded-proto'] != "https") {
res.redirect('https://' + req.get('host') + req.url);
} else {
next();
}
});
它导致重定向循环。如何在没有循环的情况下正确重定向?
尝试了您的建议,仍然无法正常工作。 Elastic Load Balancer没有设置正确的标题。 'res.set('x-forwarded-proto','https');'不起作用。 – user883499
找出为什么亚马逊没有设置标题,或尝试我的第二种技术。我注意到'res.header'与'res.set'完全相同,对不起! – Plato
第二种技术也不适用,因为负载平衡器总是向应用程序提供http(req.secure always false)请求。 – user883499