[英]How can I get the client IP from a request object with Restify?
我很難找到如何從路由訪問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;
如果代理在x-forwarded-for
標頭中設置原始IP,默認情況下會執行此操作,並且您可以非常輕松地添加到nginx之類的內容,則可以在代理后面工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.