How would you configure Kestrel to be production-ready when running standalone (without IIS or another reverse proxy in front of it), and what risks does this expose you to?
Short answer
Running Kestrel directly exposed to the internet requires manually configuring what a reverse proxy would otherwise provide: request size limits, connection/request timeouts, minimum data rates (to mitigate slow-loris style attacks), and header size limits -- Kestrel is capable…
Advertisement
AModel answer
Running Kestrel directly exposed to the internet requires manually configuring what a reverse proxy would otherwise provide: request size limits, connection/request timeouts, minimum data rates (to mitigate slow-loris style attacks), and header size limits -- Kestrel is capable of being production-ready standalone since ASP.NET Core 2.1+, but this configuration must be deliberate, and additional infrastructure-level protections (DDoS mitigation, TLS termination at a CDN edge) commonly provided by reverse proxies are then the application's own responsibility.
builder.WebHost.ConfigureKestrel(options => {
options.Limits.MaxRequestBodySize = 30_000_000;
options.Limits.MinRequestBodyDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(30);
});Real-world example
A cloud-native service running Kestrel standalone behind only a cloud load balancer (no traditional reverse proxy) explicitly configures minimum data rate limits to defend against slow-loris connection-exhaustion attacks that a reverse proxy would otherwise have mitigated automatically.
Likely follow-ups
- What specific protections does a CDN or cloud load balancer provide that Kestrel's own configuration can't fully replace?
- How do you decide whether standalone Kestrel is sufficient versus needing a dedicated reverse proxy?
Related topics