azure - 是否可以在本地使用 SSL 运行 Azure Function 应用程序?

标签 azure macos ssl .net-core azure-functions

我有一个 Azure 函数应用程序。它在本地与 HTTP 配合得很好。它在生产中也表现良好。我正在尝试在本地使用 HTTPS 运行它。我创建了一个证书,但浏览器上仍然显示证书错误。我也尝试将我的证书添加到 KeyChain Access,但结果是相同的。

如何在本地使用 SSL 证书运行我的函数?

我正在尝试从我的移动应用程序访问我的服务,但 Android 不允许我调用 HTTP 端点。

谢谢。

最佳答案

需要正确设置命令行参数,然后可以在 Visual Studio 中通过 HTTPS 启动 Azure Functions,并利用断点调试,而无需在 Visual Studio 中附加 func 进程。

  1. 安装用于本地 Azure Function 开发的工具: 微软Azure存储资源管理器 微软Azure存储模拟器 Install the Azure Functions Core Tools 或者 npm install -g azure-functions-core-tools

  2. 安装 Azure Functions Visual Studio 扩展

Azure Functions 和 Web 作业工具需要作为 Visual Studio 中的扩展安装。

enter image description here

  • 将 Azure Functions 项目配置为使用 HTTPS
  • 创建证书并将其添加到操作系统。

    openssl genrsa -des3 -passout pass:x -out server.pass.key 2048

    openssl rsa -passin pass:x -``in server.pass.key -out server.key

    openssl req -``new -key server.key -out server.csr

    openssl x509 -req -sha256 -days 365 -``in server.csr -signkey server.key -out server.crt

    New-SelfSignedCertificate -DnsName "server.com"``, "server.com" -CertStoreLocation > “cert:\LocalMachine\My”

    获取指纹 稍后使用

    $mypwd = ConvertTo-SecureString -String “1111” -Force -AsPlainText

    Get-ChildItem -Path cert:\localMachine\my\``"上面的指纹" |导出 PfxCertificate -FilePath C:\server.pfx -密码 $mypwd

  • pfx 文件复制到 Function 项目,然后配置属性以将其复制到输出。
  • enter image description here

  • 配置调试的命令行参数。
  • 应用程序参数在 Visual Studio 中以 host 开头,而不是 func!这将是命令行中的func
  • enter image description here

    或者只是在 launchSettings.json 中设置它

    {
    
    "profiles"``: {
    "FunctionApp1": {
    "commandName":` "Project",
    "commandLineArgs": "host start --useHttps --cert \"server.pfx\" --password \"1111\""
            }
        }
    }
    

    使用 Visual Studio 启动 Azure Function 项目时,将使用 HTTPS URL。这可以在启动后打开的命令行窗口中进行检查。现在可以进行断点调试,因为我们是从 Visual Studio 开始的。

    enter image description here

    如果您使用 func start –useHttps –cert “server.pfx” –password “1111” 从控制台启动此程序,则需要附加 func 进程以使用 Visual 进行断点调试工作室。

    关于azure - 是否可以在本地使用 SSL 运行 Azure Function 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70786488/

    相关文章:

    c - 如何在 Mac 上使用 C 文件创建 Unix Executive 文件

    python - pip 安装 pygraphviz : No package 'libcgraph' found

    .htaccess - 使用 htaccess 强制 SSL 和 WWW 一起使用

    azure - 如果使用 count 或 for_each 创建资源,如何在 terraform 中使用 dependent_on

    c# - Azure 身份验证 Web 应用本地主机回复 url

    macos - Xerces-C dylib 的 Mac OSX 兼容版本 (10.5-10.8)

    android - OkHttp SSLPeerUnverifiedException

    azure - 如何从 terraform 获取 Azure Security Insights 对象 ID?

    java - 如何在intellij IDE中通过maven插件添加新的azure功能

    Java SSL 连接和未知服务器证书警告