Elastic Load Balancer在Beanstalk应用中未通过X-Forwarded-For [英] Elastic Load Balancer not passing X-Forwarded-For in Beanstalk app

查看:41
本文介绍了Elastic Load Balancer在Beanstalk应用中未通过X-Forwarded-For的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试将Webapp部署到Elastic Beanstalk实例上的情况.我创建了一个准系统应用程序,该应用程序使用jstl标签简单地输出请求标头,还可以从控制器内部获取标头.

I am currently testing the deployment of our webapps onto an Elastic Beanstalk instance. I have created a barebones app that simply outputs the request headers using jstl tags, and also by grabbing the header from inside a controller.

但是,看来负载均衡器没有添加/发送X-Forwarded-For参数,所以我找不到原始IP.我收到的标头参数如下:-

However, it seems the load balancer is not adding/sending the X-Forwarded-For parameter, so I cannot find the origin IP. The header params I receive are as follows:-

    cookie: AWSELB=09D969F91EF3C3604AB87D64987C7C54D857FED9A34F717D91F616079AC29E2AD67BDF984862A60ACA38A4EB6D54DC6257C08DB00AC6FE1F7F528DAC6C84D40EF4FCBC81AB
cache-control: no-cache
connection: Keep-Alive
accept-language: en-US,en;q=0.5
host: barebones-env.elasticbeanstalk.com
x-forwarded-port: 80
accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
x-forwarded-host: barebones-env.elasticbeanstalk.com
user-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
accept-encoding: gzip, deflate
x-forwarded-server: ip-10-58-127-10.eu-west-1.compute.internal
x-forwarded-proto: http
pragma: no-cache
IP Address from Controller =    //this is blank, it should be getting servletRequest.getHeader("X-FORWARDED-FOR");

创建新的Elastic beantalk环境后,我没有更改任何设置.有人有什么主意吗?

I have not changed any settings after creating a new elastic beanstalk environment. Does anybody have any ideas?

谢谢,达米安

推荐答案

的确,负载均衡器通常会将具有自己IP地址的请求转发到其背后的服务器,并以 X-Forwarded-For 标头.但是,Elastic Load Balancer似乎比这更透明.我不知道您使用的是哪种编程语言,但是在Java/Spring环境中,通过在 HttpServletRequest 上调用 getRemoteAddr()可以很好地解决问题.换句话说,我认为您根本不需要理会 X-Forwarded-For 标头.

It is true that a load balancer will typically forward requests with its own IP address to the servers behind it, and the client's IP in an X-Forwarded-For header. However, the Elastic Load Balancer seems a bit more transparent than that. I don't know what programming language you're using, but in my Java/Spring environment I get by just fine with a call to getRemoteAddr() on my HttpServletRequest. In other words, I don't think you need to bother with the X-Forwarded-For header at all.

祝你好运!

这篇关于Elastic Load Balancer在Beanstalk应用中未通过X-Forwarded-For的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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