Pergunta

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

Foi útil?

Solução

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!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top