Elastic Load Balancer not passing X-Forwarded-For in Beanstalk app

亡梦爱人 提交于 2020-12-12 11:08:22

问题


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.

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

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

Thanks, Damian


回答1:


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.

Good Luck!



来源:https://stackoverflow.com/questions/21433472/elastic-load-balancer-not-passing-x-forwarded-for-in-beanstalk-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!