如何从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;
});
req.ip
。如果您在代理后面,请参考:http://expressjs.com/en/guide/behind-proxies.html - Roland Starke