【问题标题】:How do I force my local Azure functions server to use HTTP 2.0 instead of 1.1?如何强制我的本地 Azure 函数服务器使用 HTTP 2.0 而不是 1.1?
【发布时间】:2021-02-25 21:41:29
【问题描述】:

我在 Mac High Sierra 上使用 azure-cli v 2.8.0 和 Python 3.8。我有一个在本地运行的函数应用

func start

我用基本文件夹结构定义了我的函数...

my-func/__init__.py
my-func/function.json

function.json 文件的样子

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post",
        "get"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

我有一个 host.json 文件,看起来像

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

不确定如何/在哪里指定我想使用 HTTP 2.0 协议,但据检查员告诉我,它会出现在我使用 http 1.1 的 Angular 应用程序对我的本地服务器的请求中

如何强制我的本地函数服务器使用 HTTP 2.0?

【问题讨论】:

    标签: python-3.x azure azure-functions http2 azure-cli


    【解决方案1】:

    似乎不可能:HTTP/2 支持是 Azure 中的 Azure Functions 网络基础设施提供的一项功能,在本地不可用。

    请参阅 Azure Functions Core Tools Github 存储库上的 this issue:开发人员没有提供任何答案,但他们也没有发表任何与贡献者意见相反的言论。

    另外,正如您在Azure Functions documentation page 中看到的那样,当他们谈到支持本地启动功能的不同选项时,不可能表明支持 HTTP/2。

    如果您查看Azure Functions Core Tools Github repository 中的StartHostAction.cssource code,如果您使用HTTPS,这是一个受支持的选项,它似乎在引擎盖下将启用Krestrel。但即使在这种情况下,假设存在任何类型的环境配置属性或类似的东西来启用该功能,MacOS 中的HTTP/2 is still unsupported

    也许,一种可能性是在您的 Angular 应用程序和您的函数之间实现某种支持 HTTP/2 的代理,并通过它路由流量。

    例如,考虑使用nghttpx HTTP/2 proxy

    例如,您可以让nghttpx 在端口8443 上侦听HTTP/2 请求,如果您的函数在端口7071 上运行,则像这样从命令行运行nghttpx(示例只是图书馆文档中提供的改编版):

    nghttpx -f0.0.0.0,8443 -b127.0.0.1,7071 /path/to/server.key /path/to/server.crt
    

    您可以使用brewbuild it from source 安装它。

    【讨论】:

    • @Dave 我为您提供了一个基于nghttp2nghttpx 的新选项。我希望它有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多