.NET 6最小Web应用程序,用于在Linux上永久重定向(应用程序错误 /网站不安全)上的Azure应用程序服务

发布于 2025-02-03 23:23:31 字数 5918 浏览 3 评论 0 原文

我有一个子域,必须将任何路线重定向到主要域根:

  1. http(s)://subdomain.example.com/ => https://example.com
  2. http(s)://subdomain.example.com /{*nothing} =>

https://example.com :

using System.Net;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddHttpsRedirection(options =>
{
    options.RedirectStatusCode = (int)HttpStatusCode.PermanentRedirect;
    options.HttpsPort = 443;
});

WebApplication app = builder.Build();

app.Urls.Add("http://+");
app.Urls.Add("https://+");

app.UseHttpsRedirection();

app.MapGet("/", () => Results.Redirect("https://example.com", true, true));
app.MapGet("/{*_}", (string _) => Results.Redirect("https://example.com", true, true));

app.Run();

当我在本地运行时,一切都有效:

然后我创建了应用程序服务( Linux)在Azure中:

  • 我设置了自定义域 subdomain.example.com
  • 我添加了App Service Service Servicated证书,用于自定义子域
  • 仅在外观上

https https,迄今为止 看起来不错。但是,当我部署应用程序并运行它时,有2个问题:

  1. 打开 https://mycustomapp.azurewebsites.net 显示我据报道,当打开http(s)://subdomain.example.com时,该网站被报道为不安全(!),
  2. 我遇到了应用错误

,这是我在日志中看到的内容:


2022-06-03T03 :43:22.170878337Z ASP .NETCORE版本:6.0.3

2022-06-03T03:43:22.170881637Z注意:任何外部'/home'''/home'的数据都不持续

2022-06-06-03-03t03:43:43:43:22.46220959593333333: -apppath/home/site/wwwroot -output/opt/startup/startup.sh -defaultappfilepath/defaulthome/hostingstart/hostingstart/hostingstart.dll-bindport 8080 -bindport

8080-找不到'/home/site/wwwroot/oryx-manifest.toml'2022-06-03T03:43:22.5553445850Z

无法在明显中找到操作ID。 Generating an operation id...

2022-06-03T03:43:22.553843654Z Build Operation ID: [guid]

2022-06-03T03:43:23.236717018Z

2022-06-03T03:43:23.237393225Z Agent extension

2022-06- 03T03:43:23.237407225Z如果循环>> dotnet运行时

2022-06-03T03:43:23.277833149Z dotnet运行时6.0写入输出脚本to'/opt/startup/startup.sh'2022-06-06-03T03

43:43:23.358910299Z提供了启动用户...

: -03T03:43:25.470314040Z未经治疗的异常。 System.InvalidoperationException:无法配置HTTPS端点。没有指定服务器证书,默认开发人员证书找不到或已过时。

2022-06-03T03:43:25.470359841Z生成开发人员证书运行“ dotnet dev-certs https”。要信任证书(仅Windows和MacOS)运行“ Dotnet Dev-Certs HTTPS-Trust”。

2022-06-03T03:43:25.470366541Z有关配置https的更多信息,请参见

2022-06-03T03:43:25.470370941Z在Microsoft.aspnetcore.hosting.listenoptionshttpsextensions.usehttps(LinctoPtions) .listenoptionshttpsextensions.usehttps

(听力侦听)

2022-06-03T03:43:25.470379341Z在Microsoft.aspnetcore.server.kestrel.core.core.internal.address.address.addressbinder.address.address.anddresseststrategy.bindastrate.bindasternc(地址BindContAsync)

Microsoft的 383541Z .AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)

2022-06-03T03:43:25.470387541Z at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync (comcellationToken concellationToken)

在Microsoft.aspnetcore.server.kestrel.core.kestrel.kestrel.kestrelsererserersererserersererserver.startasherimpl.startasherimpl.startashasenc [tcontext](tcontext](tcontext] 25.470405941Z

2022-06-03T03 :43:25.470402041Z 在Microsoft.aspnetcore.hosting.genericwebhostservice.startasernc(CancellationToken concellationToken

25.470409541Z在Microsoft.extensions.hosting.hosting.internal.host.host.startartartation 3.4.internal.startartation 3 cancellation 0. 3:25.470413041Z

)2022-06-03T03 :43: at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

2022-06-03T03:43:25.470416641Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

2022-06-03T03: 43:25.470426442Z在Microsoft.extensions.hosting.hosting.hostingabstractionshostextensions.run(iHost主机)

25.470430142Z at microsoft.aspnetcore.aspnetcore.builder.builder.webapplic.webapplic.webapplication.rul.rir.rir.rir.rirlant(ryl)

2022-06-03T03:43 :43: 25.472178560Z在程序中。 app.run()是]

:41.244915770Z无法打开输出/home/logs/dumps/coredump.d26e6752ab2.36.1654227802:2否此类文件或目录20222-0333333T333T333T33T33T33T33T33TT

2022-06-03T03: 43 Z流程的收集状态36 dotnet

2022-06-03T03:43:41.253793945Z崩溃线程00000024信号00000006

2022-06-03T03:43:43:41.253799545Z Writing Minidump to Heap to File/file/hog.log.log.log.46/ 1654227802

2022-06-03T03:43:41.762563322z/opt/startup/startup.sh:第10行:36中止(核心倾销)dotnet permanentRedectMinimal.dll

20222-06-06-06-03-03t03:43:42.4444z信息,以响应温暖用于容器Annuaire_0_4715A3E4。经过的时间= 19.6895811 SEC

2022-06-03T03:43:42.508Z错误 - 网站BLAH的容器BLAH_0_4715A3E4已退出,失败站点开始

2022-06-03T03:43:42.511Z错误 - 容器错误 - 容器Blah_0_4777747715a3e444211z erragy-doct端口:8080,失败站点开始。请参阅容器日志以进行调试。

2022-06-03T03:43:42.520Z信息 - 停止网站,因为它在启动过程中失败了。


I have a subdomain which must redirect any route to a main domain root:

  1. http(s)://subdomain.example.com/ => https://example.com
  2. http(s)://subdomain.example.com/{*anything} => https://example.com

So, I have created a minimal .NET 6 web app:

using System.Net;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddHttpsRedirection(options =>
{
    options.RedirectStatusCode = (int)HttpStatusCode.PermanentRedirect;
    options.HttpsPort = 443;
});

WebApplication app = builder.Build();

app.Urls.Add("http://+");
app.Urls.Add("https://+");

app.UseHttpsRedirection();

app.MapGet("/", () => Results.Redirect("https://example.com", true, true));
app.MapGet("/{*_}", (string _) => Results.Redirect("https://example.com", true, true));

app.Run();

When I run it locally, everything works:

Then I created App Service (Linux) in Azure for which:

  • I set up my custom domain subdomain.example.com
  • I added App Service Managed certificate for my custom subdomain
  • HTTPS only is ON

Looks good so far. But when I deploy my app and run it, 2 problems:

  1. opening https://mycustomapp.azurewebsites.net shows me This site has been reported as unsafe (!)
  2. when open http(s)://subdomain.example.com I get application error

And here's what I see in the logs:


2022-06-03T03:43:22.170878337Z ASP .NETCore Version: 6.0.3

2022-06-03T03:43:22.170881637Z Note: Any data outside '/home' is not persisted

2022-06-03T03:43:22.462209593Z Running oryx create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -defaultAppFilePath /defaulthome/hostingstart/hostingstart.dll -bindPort 8080 -userStartupCommand 'dotnet PermanentRedirectMinimal.dll'

2022-06-03T03:43:22.553430350Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'

2022-06-03T03:43:22.553445850Z Could not find operation ID in manifest. Generating an operation id...

2022-06-03T03:43:22.553843654Z Build Operation ID: [guid]

2022-06-03T03:43:23.236717018Z

2022-06-03T03:43:23.237393225Z Agent extension

2022-06-03T03:43:23.237407225Z Before if loop >> DotNet Runtime

2022-06-03T03:43:23.277833149Z DotNet Runtime 6.0Writing output script to '/opt/startup/startup.sh'

2022-06-03T03:43:23.358910299Z Running user provided startup command...

2022-06-03T03:43:25.470314040Z 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.

2022-06-03T03:43:25.470359841Z To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

2022-06-03T03:43:25.470366541Z For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

2022-06-03T03:43:25.470370941Z at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)

2022-06-03T03:43:25.470375241Z at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)

2022-06-03T03:43:25.470379341Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)

2022-06-03T03:43:25.470383541Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)

2022-06-03T03:43:25.470387541Z at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)

2022-06-03T03:43:25.470402041Z at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

2022-06-03T03:43:25.470405941Z at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

2022-06-03T03:43:25.470409541Z at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

2022-06-03T03:43:25.470413041Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

2022-06-03T03:43:25.470416641Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

2022-06-03T03:43:25.470426442Z at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

2022-06-03T03:43:25.470430142Z at Microsoft.AspNetCore.Builder.WebApplication.Run(String url)

2022-06-03T03:43:25.472178560Z at Program.$(String[] args) in e:...\PermanentRedirectMinimal\Program.cs:line 22 [ ==> where app.Run() is ]

2022-06-03T03:43:41.244915770Z Could not open output /home/logs/dumps/coredump.d26e6752ab2d.36.1654227802: 2 No such file or directory

2022-06-03T03:43:41.253765645Z Gathering state for process 36 dotnet

2022-06-03T03:43:41.253793945Z Crashing thread 00000024 signal 00000006

2022-06-03T03:43:41.253799545Z Writing minidump with heap to file /home/logs/dumps/coredump.d26e6752ab2d.36.1654227802

2022-06-03T03:43:41.762563322Z /opt/startup/startup.sh: line 10: 36 Aborted (core dumped) dotnet PermanentRedirectMinimal.dll

2022-06-03T03:43:42.474Z INFO - Waiting for response to warmup request for container annuaire_0_4715a3e4. Elapsed time = 19.6895811 sec

2022-06-03T03:43:42.508Z ERROR - Container blah_0_4715a3e4 for site blah has exited, failing site start

2022-06-03T03:43:42.511Z ERROR - Container blah_0_4715a3e4 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.

2022-06-03T03:43:42.520Z INFO - Stopping site blah because it failed during startup.


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野味少女 2025-02-10 23:23:31

正如Azure支持确认的那样,Linux App Service不支持此方案。 :( Azure力量。

As confirmed by Azure Support, this scenario is not supported for Linux App Service. :( Azure power.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文