容器的 Azure Web 应用程序在升级到 .net8 后出现 https 错误

问题描述 投票:0回答:1

我有一个用于 Azure 中运行 Linux 的容器的 Web 应用程序,从容器注册表获取 docker 映像。 我有一个 .net7 web 应用程序,运行良好。在我将其更新为 .net8 并将默认端口设置为新推荐的端口 (8080) 后,Web 应用程序因 https 错误而停止运行。

详情:

Dockerfile(相关部分):

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 443

Web 应用程序设置(环境变量):

"ASPNETCORE_HTTP_PORTS": "8080",
"ASPNETCORE_HTTPS_PORTS": "443"

HTTPS Only: On

网络应用程序日志:

2024-01-21T22:48:44.411145098Z {"Timestamp":"2024-01-21T22:48:44.2947105+00:00","Level":"Error","MessageTemplate":"Hosting failed to start","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.\nTo generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.\nFor more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.\n   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(ListenOptions[] listenOptions, AddressBindContext context, Func`2 useHttps, CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)\n   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)\n   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)","Properties":{"EventId":{"Id":11,"Name":"HostedServiceStartupFaulted"},"SourceContext":"Microsoft.Extensions.Hosting.Internal.Host"}}
2024-01-21T22:48:44.411193001Z {"Timestamp":"2024-01-21T22:48:44.3617139+00:00","Level":"Fatal","MessageTemplate":"Ouch! Host building terminated unexpectedly","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.\nTo generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.\nFor more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.\n   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(ListenOptions[] listenOptions, AddressBindContext context, Func`2 useHttps, CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)\n   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)\n   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)\n   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)\n   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)\n   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)\n   at Program.<Main>$(String[] args) in /src/testProject.Core/Program.cs:line 247"}
/home/LogFiles/2024_01_21_lw1sdlwk0007NS_docker.log  (https://testProject-api.scm.azurewebsites.net/api/vfs/LogFiles/2024_01_21_lw1sdlwk0007NS_docker.log)
2024-01-21T22:48:42.076Z INFO  -  Status: Image is up to date for mcr.microsoft.com/appsvc/middleware:stage5
2024-01-21T22:48:42.145Z INFO  - Pull Image successful, Time taken: 1 Seconds
2024-01-21T22:48:42.370Z INFO  - Starting container for site
2024-01-21T22:48:42.378Z INFO  - docker run -d -p 5227:8181 --name testProject-api_0_1334c363_middleware -e WEBSITE_CORS_ALLOWED_ORIGINS=https://testProject-api.azurewebsites.net -e WEBSITE_CORS_SUPPORT_CREDENTIALS=True -e DOCKER_CUSTOM_IMAGE_NAME=projecttestcr.azurecr.io/testProjectapi:458 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=testProject-api -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=testProject-api.azurewebsites.net -e WEBSITE_INSTANCE_ID=1234e06e53eec8d5c5f366b3597570d9375ce0ef48cc72401db89ecd02d82bd0 mcr.microsoft.com/appsvc/middleware:stage5 /Host.ListenUrl=http://0.0.0.0:8181 /Host.DestinationHostUrl=http://172.16.254.3:8080 /Host.UseFileLogging=true
2024-01-21T22:48:42.381Z INFO  - Logging is not enabled for thi2024-01-21T22:48:47.449Z INFO  - Initiating warmup request to container testProject-api_0_1334c363 for site testProject-api
2024-01-21T22:48:47.575Z ERROR - Container testProject-api_0_1334c363 for site testProject-api has exited, failing site start
2024-01-21T22:48:47.577Z INFO  - Initiating warmup request to container testProject-api_0_1334c363_middleware for site testProject-api
2024-01-21T22:48:57.980Z INFO  - Container testProject-api_0_1334c363_middleware for site testProject-api initialized successfully and is ready to serve requests.
2024-01-21T22:48:58.017Z ERROR - Container testProject-api_0_1334c363 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2024-01-21T22:48:58.163Z INFO  - Stopping site testProject-api because it failed during startup.Ending Log Tail of existing logs ---Starting Live Log Stream ---
2024-01-21T22:51:26  No new trace in the past 1 min(s).

我还需要设置什么才能使其正常工作?

azure https dockerfile .net-8.0 azure-container-apps
1个回答
0
投票

根据建议,根据信息此链接建议我将容器设置为使用 http 调用而不是 https 调用。为此,我删除了

EXPOSE 443

来自 dockerfile 并删除了

"ASPNETCORE_HTTPS_PORTS": "443"

来自环境变量 并删除了

app.UseHttpsRedirection();

来自program.cs。 现在,应用程序在发布后可以正确启动。唯一的缺点是,当我想在本地主机环境上测试应用程序时,我需要将

EXPOSE 443
重新添加到 dockerfile 中。

© www.soinside.com 2019 - 2024. All rights reserved.