我有一个子域,它必须将任何路由重定向到主域名根:
-
http://subdomain.example.com/=>
https://example.com
-
http://subdomain.example.com/{*anything}=>
https://example.com
因此,我创建了一个最小的.NET 6 web应用程序:
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();
当我在本地运行它时,一切都正常:
然后我在Azure中创建了应用程序服务(Linux),用于:
-
我设置了自定义域
子域example.com
-
我为我的自定义子域添加了应用服务管理证书
-
仅HTTPS打开
到目前为止看起来不错。但当我部署并运行我的应用程序时,有两个问题:
-
开放
https://mycustomapp.azurewebsites.net
给我看
此网站已被报告为不安全
(!)
-
当打开http://subdomain.example.com时,我收到应用程序错误
下面是我在日志中看到的内容:
2022-06-03T03:43:22.17087837Z ASP.NETCore版本:6.0.3
2022-06-03T03:43:22.170881637Z注意:“/home”之外的任何数据都不会持久化
2022-06-03T03:43:22.462209593Z正在运行oryx创建脚本-appPath/home/site/wwwroot-output/opt/startup.sh-defaultAppFilePath/defaulthome/hostingstart/hostingstar.dll-bindPort 8080-userStartupCommand“dotnet PermanentRedirectMinimal.dll”
2022-06-03T03:43:22.5553430350Z在“/home/site/wwwwroot/oryx manifest.toml”中找不到生成清单文件
2022-06-03T03:43:22.5553445850Z在清单中找不到操作ID。正在生成操作id。。。
2022-06-03T03:43:22.5553843654Z构建操作ID:[guid]
2022-06-03t3:43:23.236717018Z
2022-06-03T03:43:23.237393225Z代理延期
2022-06-03T03:43:23.237407225Z如果循环之前>>DotNet运行时
2022-06-03T03:43:23.277833149Z DotNet Runtime 6.0将输出脚本写入“/opt/startup/startment.sh”
2022-06-03T03:43:23.358910299Z运行用户提供的启动命令。。。
2022-06-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的更多信息,请参阅
https://go.microsoft.com/fwlink/?linkid=848054
。
2022-06-03T03:43:25.470370941Z,位于Microsoft.AspNetCore.Hosting.ListOptionsHttpsExtensions.UseHttps(ListOptions ListenOptions,Action`1 configureOptions)
2022-06-03T03:43:25.470375241Z在Microsoft.AspNetCore.Hosting.ListOptionsHttpsExtensions.UseHttps(ListOptions ListenOptions)
2022-06-03T03:43:25.470379341Z,位于Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext上下文,CancellationToken取消令牌)
2022-06-03T03:43:25.470383541Z,位于Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions,AddressBindContext上下文,CancellationToken cancellionToken)
2022-06-03T03:43:25.470387541Z在Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellionToken)
2022-06-03T03:43:25.470402041Z,位于Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1应用程序,CancellationToken取消令牌)
2022-06-03T03:43:25.470405941Z在Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellionToken)
2022-06-03T03:43:25.470409541Z在Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellionToken)
2022-06-03T03:43:25.470413041Z在Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost主机,CancellationToken令牌)
2022-06-03T03:43:25.470416641Z在Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost主机,CancellationToken令牌)
2022-06-03T03:43:25.470426442Z在Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
2022-06-03T03:43:25.470430142Z在Microsoft.AspNetCore.Builder.WebApplication.Run(字符串url)
2022-06-03T03:43:25.472178560Z在节目中$(String[]args)在e:。。。\PermanentRedirectMinimal\Program.cs:line 22[===>app.Run()所在位置]
2022-06-03T03:43:41.244915770Z无法打开output/home/logs/dumps/coredump.d26e6752ab2d.36.1654227802:2没有这样的文件或目录
2022-06-03T03:43:41.253765645Z正在收集进程36的状态dotnet
2022-06-03T03:43:41.253793945Z断线00000024信号00000006
2022-06-03T03:43:41.253799545Z将带堆的小型转储写入file/home/logs/dumps/coredump.d26e6752ab2d.36.1654227802
2022-06-03T03:43:41.762563322Z/opt/startup/startup.sh:行10:36中止(转储内核)dotnet PermanentRedirectMinimal.dll
2022-06-03T03:43:42.474Z信息-正在等待对容器annuaire_0_4715a3e4的预热请求的响应。运行时间=19.6895811秒
2022-06-03T03:43:42.508Z错误-站点blah的容器blah_0_4715a3e4已退出,站点启动失败
2022-06-03T03:43:42.511Z错误-容器blah_0_4715a3e4没有响应端口8080上的HTTP ping,站点启动失败。有关调试,请参阅容器日志。
2022-06-03T03:43:42.520Z信息-正在停止站点blah,因为它在启动过程中失败。