I'm connecting to my app, which is running on an AWS EC2 instance. I'm trying to get the client IP address but it is showing up as 127.0.0.1
I've tried retrieving it with both req.ip
and req.connection.remoteAddress
. Is there a way to get the IP address that's not the localhost IP?
I'm connecting to my app, which is running on an AWS EC2 instance. I'm trying to get the client IP address but it is showing up as 127.0.0.1
I've tried retrieving it with both req.ip
and req.connection.remoteAddress
. Is there a way to get the IP address that's not the localhost IP?
- stackoverflow./questions/19266329/node-js-get-clients-ip I think this guy asked the same question – AzaFromKaza Commented Jan 28, 2015 at 7:02
1 Answer
Reset to default 7If you're proxying requests through something like Nginx, then you can configure express to respect the X-Forwarded-For
header when getting req.ip
:
app.set('trust proxy', 'loopback');
http://expressjs./api.html#app.set