【问题标题】:How can i get the client IP address in Flask running on an Azure Linux Web App?如何在 Azure Linux Web App 上运行的 Flask 中获取客户端 IP 地址?
【发布时间】:2019-11-05 23:48:20
【问题描述】:

我在 Azure Linux Web 应用程序上运行一个烧瓶站点。我已经到了需要知道客户端IP地址的地步。我已经阅读了很多关于在代理后面访问客户端 IP 地址的线程,并且您必须更新您的 nginx 配置文件以通过代理传递此信息,但是,我认为我的 Azure Linux Web 应用程序没有运行 nginx网络服务器。

如何知道我的 Azure Linux Web 应用程序正在运行哪个 Web 服务器,以及如何开始在我的 Flask 应用程序的 python 代码中查找客户端 IP 地址?

【问题讨论】:

  • 你至少试过request.remote_addr吗?
  • @noslenkwah 是的,我已经尝试过 request.remote_addr 和其他请求环境变量。似乎要填充其中的任何一个,我需要更新我的未知配置以使值从代理服务器传递。但是我如何发现我的代理服务器是什么以及我正在使用什么网络服务器?

标签: python azure flask


【解决方案1】:

在 Azure Linux Web App 中,它将通过反向代理更改来自 Internet 的请求。所以需要使用request包来获取客户端。这里的示例代码:

clinet_ips = request.headers.getlist("X-Forwarded-For")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 2012-02-16
    • 1970-01-01
    • 2015-12-20
    • 2016-03-29
    相关资源
    最近更新 更多