最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论