use*_*499 6 load-balancing amazon-ec2 amazon-web-services node.js express
我试图强制所有http请求到https请求,我正面临问题,因为弹性负载均衡器没有在请求中填充x-forwarded-proto标头.
这是我正在使用的代码,因此导致重定向循环.我该如何解决这个问题?
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);
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7003 次 |
最近记录: |