admin管理员组

文章数量:1429008

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?

Share Improve this question asked Jan 28, 2015 at 6:58 jordanjordan 10.9k10 gold badges46 silver badges81 bronze badges 1
  • stackoverflow./questions/19266329/node-js-get-clients-ip I think this guy asked the same question – AzaFromKaza Commented Jan 28, 2015 at 7:02
Add a ment  | 

1 Answer 1

Reset to default 7

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./api.html#app.set

本文标签: JavaScriptNodeJSExpressTrying to get client IP from request objectshows 127001Stack Overflow