【问题标题】:How to accept connections from local network on Azure Functions (v2)?如何在 Azure Functions (v2) 上接受来自本地网络的连接?
【发布时间】:2018-08-22 08:59:02
【问题描述】:

我正在尝试使用 Xamarin Forms 开发 @AzureFunctions。 但它不接受来自手机的连接。

如何在 Visual Studio 2017 上配置 Azure Functions 的主机、端口以启用来自 * 的连接而不是 localhost 连接?

如何在 Azure Functions (v2) 上接受来自本地网络的连接?

如何在 Visual Studio 2017 上配置主机:Azure Functions 的端口?

我希望它像 ASP.Net Core (.UseUrls("http://+:7071")) 一样接受:

Now listening on: http://[::]:7071

但它只是在听

http://localhost:7071

GitHub 问题: 如何配置 Azure Functions (v2) 监听主机/域? https://github.com/Azure/azure-functions-core-tools/issues/537

【问题讨论】:

  • 您是尝试从真实设备还是从模拟器连接?我想您需要先将您的设备连接到同一个网络,并确保您可以从该设备访问计算机,然后它应该很容易
  • 我使用的是真实设备,在同一个 WiFi 上,但无法连接,Azure Functions 仅在 localhost 上侦听
  • 截图显示函数是由http请求触发的。请求是来自电话还是来自其他地方?
  • 你不能在 localhost 以外的任何地方收听。根据文档,您可以从command lineconfig 更改端口,仅此而已。 (几个月前,我浪费了大约三天的时间试图解决同一件事......)
  • 对此有一个开放的feature request,有人确实想出了一个反向代理解决方法......

标签: azure visual-studio-2017 azure-functions


【解决方案1】:

最近对 Azure Functions (v2) 进行的更新解决了这个问题。
现在 Azure Functions 侦听 IP 0.0.0.0

Hosting environment: Production
Content root path: C:\Users\tonyv\source\repos\SistemaMulti\WebAPI\bin\Debug\netstandard2.0
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

所以我们可以只选择计算机 IP 地址,例如 http://192.168.15.16:7071/api/Ping,然后使用它,Azure Functions 将按预期在 LAN 上响应。

https://github.com/Azure/azure-functions-core-tools/issues/537#issuecomment-399239887

【讨论】:

    【解决方案2】:

    您可以通过在调试参数中指定func host 命令并使用-p 开关来配置端口,但主机名被硬编码为localhost,如源代码here 所示。

    GitHub 上有一个未解决的问题请求此功能:https://github.com/Azure/azure-functions-core-tools/issues/174,所以如果这对您很重要并且您还没有这样做,请务必加入。项目所有者已经在该线程上。

    此外,由于这都是开源的,您可以选择提交 PR 以添加此功能。我绝对鼓励这样做,因为团队通常很难优先考虑没有广泛或战略应用的场景(80% 的案例),所以 PR 可以非常有助于完善剩余的 20% 用例的长尾.

    【讨论】:

    • 这个场景很重要,例如,如何使用手机开发移动应用程序并在 PC 上调试 Azure Function。 Azure 函数已锁定到 localhost。没有简单的方法为 IP 或域名配置它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 2022-10-05
    相关资源
    最近更新 更多