Reputation: 10722
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?
Upvotes: 2
Views: 3015
Reputation: 14327
If 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.com/api.html#app.set
Upvotes: 7