【问题标题】:How to get client IP address in Azure Functions node.js?如何在 Azure Functions node.js 中获取客户端 IP 地址?
【发布时间】:2017-06-19 15:02:36
【问题描述】:

我在 node.js 上编写了一个 Azure 函数。如何检索调用该函数的客户端的 IP 地址?

到目前为止我发现了什么:

  1. answer 回答相同的问题,但使用 C#。
  2. 可以从标题中读取:

    module.exports = function (context, req) {
        var ip = req.headers['x-forwarded-for']    
    }
    

通过这种方式获取ip可靠吗,因为它可以在通往函数的途中轻松更改?

【问题讨论】:

  • 是的,它是可靠的,因为 Azure Web 服务器将覆盖 x-forwarded-for,因为它知道它是从负载均衡器转发的。
  • 谢谢阿卡什!你能把这个评论作为答案吗?

标签: node.js azure azure-functions


【解决方案1】:

是的,它是可靠的,因为 Azure Web 服务器将覆盖 x-forwarded-for,因为它知道它是从负载均衡器转发的。

【讨论】:

    【解决方案2】:

    如果您使用express,请考虑设置app.set('trust proxy');

    欲了解更多信息,请查看express manual page on 'Express behing proxies'

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 1970-01-01
      • 2012-03-14
      • 2012-02-16
      • 2019-01-14
      • 2021-10-22
      相关资源
      最近更新 更多