最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Nodejs, Express - Trying to get client IP from request object - shows 127.0.0.1 - Stack Overflow

matteradmin7PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far