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
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???
The easiest way to find your IP address in Node. js is to pull the client IP address from the incoming HTTP request object. If you are running Express in your Node app, this is very easy to do. Access the socket field of the Express request object, and then look up the remoteAddress property of that field.
Elastic Beanstalk routes outbound traffic through the NAT gateway. You can identify the source of the outbound traffic from the backend instances by the Elastic IP address. The Elastic IP address is a static IP address required by the NAT gateway.
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.
const _ = require('lodash');
const ipAddress = _.split(req.header('X-Forwarded-For'), ',');
ipadd = _.trim(_.first(ipAddress));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With