docker 未处理异常,系统操作无效异常:无法配置HTTPS端点,数字海洋- AppPlatform

2ekbmq32  于 2023-03-07  发布在  Docker
关注(0)|答案(1)|浏览(254)

我正在尝试使用Apps Platform将. NET Core 6.0项目部署到数字海洋。但我一次又一次地遇到此异常:
未处理异常,系统操作无效异常:无法配置HTTPS终结点。未指定服务器证书,并且找不到默认开发人员证书或该证书已过期。
到目前为止,我已经尝试了很多方法和变体。针对此异常的其他解决方案建议在本地计算机上运行以下命令:

dotnet dev-certs https --clean
dotnet dev-certs https --trust

但由于这是部署到应用程序平台,我认为这些不会工作。我甚至尝试在Dockerfile中偷偷输入dotnet dev-certs https命令,但发生了相同的异常。
以下是我目前所做的工作:

  • 停靠文件:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["/Reservations.Api/Reservations.Api.csproj", "Reservations.Api/"]
COPY ["/Reservations.Application/Reservations.Application.csproj", "Reservations.Application/"]
COPY ["/Reservations.Persistance/Reservations.Persistance.csproj", "Reservations.Persistance/"]
COPY ["/Reservations.Security/Reservations.Security.csproj", "Reservations.Security/"]
COPY ["/Reservations.Domain/Reservations.Domain.csproj", "Reservations.Domain/"]
COPY ["/Reservations.UnitTests/Reservations.UnitTests.csproj", "Reservations.UnitTests/"]
RUN dotnet restore "Reservations.Api/Reservations.Api.csproj"
COPY . .
RUN dotnet build "Reservations.Api/Reservations.Api.csproj" -c Release -o /src/build
RUN dotnet dev-certs https

FROM build AS publish
RUN dotnet publish "Reservations.Api/Reservations.Api.csproj" -c Release -o /src/publish

FROM base AS final
WORKDIR /src
COPY --from=publish /src/publish .
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_URLS="https://+:80;https://+:443;"
ENTRYPOINT ["dotnet", "Reservations.Api.dll"]
  • launchsettings.json
{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:44641",
      "sslPort": 44366
    }
  },
  "profiles": {
    "Reservations.Api": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7202;http://localhost:5202",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "publishAllPorts": true,
      "useSSL": false,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_URLS": "https://+:80;"
      },
      "httpPort": 8080,
      "applicationUrl": "http://+:8080;"
    }
  }
}
  • 在Program.cs中包含app.UseHttpsRedirection();
  • 部署日志错误:
[2023-03-01 15:39:53] warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]

[2023-03-01 15:39:53]       No XML encryptor configured. Key {8cbcf317-aff6-4a80-90fa-539eeaf0de94} may be persisted to storage in unencrypted form.

[2023-03-01 15:39:53] Unhandled exception. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

[2023-03-01 15:39:53] To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

[2023-03-01 15:39:53] For more information on configuring HTTPS see https://go.microsoft.com/fwlin

我没有主意了,所以任何帮助都将不胜感激。

2vuwiymt

2vuwiymt1#

我已经解决了这个问题,删除了任何类似HTTPS的地方,并将应用程序调整为只使用HTTP的流量。

"Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "publishAllPorts": true,
      "useSSL": false,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
=>      "ASPNETCORE_URLS": "https://+:80;"
      },
      "httpPort": 8080,
      "applicationUrl": "http://+:8080;"
    }

在标记的行中,我从"https://+:80;",使其成为" http://+80;"。另外,我从Program.cs中删除了app.UseHttpsRedirection();
重点是:App Platforms将处理应用的HTTP安全性,这意味着您无需在应用内提供任何HTTPS配置。

相关问题