如何在node.js express中获取IP地址

用户名

我们如何从node.js获取IP地址我尝试了很多方法,但它不起作用并返回:: ffff:127.0.0.1,请给我一些建议

这是我的代码:

app.put('/update-user-info', function(req, res){
  // it's doesn't work and return ::ffff:127.0.0.1
  var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress ||  req.socket.remoteAddress || req.connection.socket.remoteAddress; 
});
cse_vikashgupta

正如GuroKing所说,我将再增加一点。

--Add app.set('trust proxy', true)

在nginx.conf文件中:

proxy_set_header  X-Real-IP  $remote_addr;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章