Amazon弹性负载均衡器不填充的X转发,原标题 [英] Amazon Elastic load balancer is not populating x-forwarded-proto header

查看:201
本文介绍了Amazon弹性负载均衡器不填充的X转发,原标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图迫使所有的HTTP请求,HTTPS请求,我所面临的问题,弹性负载均衡器不填充的X转发,原头的请求。

这是在code我使用的,它是导致重定向因为这个循环。我将如何解决这个问题?

  app.use(功能(REQ,水库,下一个){
    的console.log('请求头='+ JSON.stringify(req.headers));
    的console.log('请求协议='+ JSON.stringify(req.protocol));
    VAR模式=(req.headers ['X-转发,原] ||'').toLowerCase();
    如果(架构===HTTPS){
       下一个();
    } 其他 {
       res.redirect(将https://+ req.headers.host + req.url);
    }
});
 

解决方案

这听起来像你ELB听众可能对TCP而不是HTTP进行配置。配置了TCP,它不会增加的X转发,原或X - 转发,对于

I am trying to force all http requests to https requests and I am facing the problem as elastic load balancer not populating x-forwarded-proto header in the request.

This is the code I am using and it is causing redirect loop because of this. How would I fix this problem?

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);
    }
});

解决方案

It sounds like your ELB listeners might be configured for TCP instead of HTTP. Configured for TCP, it will not add X-Forwarded-Proto or X-Forwarded-For.

这篇关于Amazon弹性负载均衡器不填充的X转发,原标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆