如何使用Restify从请求对象获取客户端IP?

问题描述:

我很难找到如何从路由访问REST客户端的IP地址。如何使用Restify从请求对象获取客户端IP?

server.get('api/foo', function(req, res, next) { 
    // How can I access the IP address of the requester from here? 
} 
+1

尝试检查'req'对象。 – Tony 2015-01-26 20:42:33

这工作:

req.connection.remoteAddress

+0

这是不工作在我的iis – 2017-11-06 12:28:50

+0

loacal其工作 – 2017-11-06 12:29:04

其他的答案将不使用代理的工作,你会在这种情况下获得的代理服务器地址。

req.headers['x-forwarded-for'] || req.connection.remoteAddress; 

将工作背后的代理,如果代理设置原始IP在x-forwarded-for头很多在默认情况下做的,你可以很容易的添加喜欢的东西nginx的。