Kestrel 是一个跨平台的适用于 ASP.NET Core 的 Web 服务器。
何时结合使用 Kestrel 和反向代理
可以单独使用 Kestrel,也可以将其与反向代理服务器(如 IIS、Nginx 或 Apache)结合使用。 反向代理服务器接收到来自 Internet 的 HTTP 请求,并在进行一些初步处理后将这些请求转发到 Kestrel。


如何在 ASP.NET Core 应用中使用 Kestrel
默认情况下,ASP.NET Core 项目模板使用 Kestrel。 在 Program.cs 中,模板代码调用 CreateDefaultBuilder,后者在后台调用 UseKestrel。
public static void Main (string[] args) {
CreateWebHostBuilder (args).Build ().Run ();
}
public static IWebHostBuilder CreateWebHostBuilder (string[] args) =>
WebHost
.CreateDefaultBuilder (args)
.UseStartup<Startup> ();
Kestrel 选项
.UseKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 100;
options.Limits.MaxConcurrentUpgradedConnections = 100;
options.Limits.MaxRequestBodySize = 10 * 1024;
options.Limits.MinRequestBodyDataRate =
new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
options.Limits.MinResponseDataRate =
new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
options.Listen(IPAddress.Loopback, 5000);
options.Listen(IPAddress.Loopback, 5001, listenOptions =>
{
listenOptions.UseHttps("testCert.pfx", "testPassword");
});
});
终结点配置
默认情况下,ASP.NET Core 绑定到:
http://localhost:5000
https://localhost:5001(存在本地开发证书时)
本文介绍Kestrel作为ASP.NET Core的跨平台Web服务器的使用方式,以及如何通过配置选项来优化其性能。同时,探讨了Kestrel与反向代理服务器如IIS、Nginx或Apache的结合使用,以实现更安全、高效的互联网应用部署。

273

被折叠的 条评论
为什么被折叠?



