我很難找到如何從路由訪問REST客戶端的IP地址。如何使用Restify從請求對象獲取客戶端IP?
server.get('api/foo', function(req, res, next) {
// How can I access the IP address of the requester from here?
}
我很難找到如何從路由訪問REST客戶端的IP地址。如何使用Restify從請求對象獲取客戶端IP?
server.get('api/foo', function(req, res, next) {
// How can I access the IP address of the requester from here?
}
這工作:
req.connection.remoteAddress
這是不工作在我的iis – 2017-11-06 12:28:50
loacal其工作 – 2017-11-06 12:29:04
其他的答案將不使用代理的工作,你會在這種情況下獲得的代理服務器地址。
req.headers['x-forwarded-for'] || req.connection.remoteAddress;
將工作背後的代理,如果代理設置原始IP在x-forwarded-for
頭很多在默認情況下做的,你可以很容易的添加喜歡的東西nginx的。
嘗試檢查'req'對象。 – Tony 2015-01-26 20:42:33