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

我很难find如何从路由访问REST客户端的IP地址。

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

这工作:

req.connection.remoteAddress

其他答案不会在代理后面工作,您将在这些情况下获得代理服务器地址。

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

如果代理将原始IP设置为x-forwarded-for标头,那么在代理后面工作会很方便,您可以很容易地添加到像nginx这样的东西。