Question:
I am using elastic beanstalk with ngnix proxy server. my application code was on node.js express framework. I am trying to access client ip via following code
1 2 3 4 |
var ip = event.headers['x-forwarded-for'] || event.connection.remoteAddress || event.socket.remoteAddress || event.connection.socket.remoteAddress; |
but i always getting same client ip for all incoming request. I think it will be the proxy server’s ip address.
How to access real client address from my application???
Answer:
I defer with @austince, the Client IP will be the first entry in the list for Elastic Beanstalk.
Example:
X-Forwarded-For: 182.12.12.123, 78.13.13.123
In case anyone, come looking for example code, here is what I have used in my project.
1 2 3 4 |
const _ = require('lodash'); const ipAddress = _.split(req.header('X-Forwarded-For'), ','); ipadd = _.trim(_.first(ipAddress)); |