Kestrel in ASP.NET Core
Kestrel is the cross-platform web server included and used by default in ASP.NET Core applications. It's lightweight, fast, and designed to handle both development and production environments.
What is Kestrel?
Kestrel is:
-
A web server that listens for HTTP requests and forwards them to your ASP.NET Core application.
-
Cross-platform and built on top of libuv (older versions) or Sockets (newer versions).
-
The default web server in ASP.NET Core since version 1.0.
ASP.NET Core Hosting Model with Kestrel
Kestrel vs IIS/Nginx/Apache
Feature | Kestrel | IIS/Nginx/Apache |
---|---|---|
Type | Application Web Server | Reverse Proxy / Full Web Server |
Cross-platform | ✅ Yes | ❌ IIS, ✅ Nginx/Apache |
Static file handling | ✅ But basic | ✅ Optimized |
TLS/HTTPS support | ✅ Yes | ✅ Yes |
Reverse Proxy Required? | Optional (Prod recommended) | Not needed (they are full servers) |
Use Case | ASP.NET Core apps | General purpose + ASP.NET Core |
In production, it's recommended to use Kestrel behind a reverse proxy (like IIS or Nginx) for enhanced security, load balancing, and better handling of TLS, logs, and static files.
Configuring Kestrel
You can configure Kestrel in Program.cs
(or Startup.cs
in older versions):
Basic Example (ASP.NET Core 6+ / 7+):
HTTPS with Kestrel
Kestrel supports HTTPS with certificates. You can configure it in appsettings.json
:
Or configure it programmatically:
Performance
Kestrel is high-performance and asynchronous, designed to handle thousands of concurrent connections. Microsoft benchmarks show Kestrel to be among the fastest web servers available.
Features and Limits in Kestrel
You can set various limits:
When to Use Kestrel Directly
-
For microservices or containerized applications in Docker/Kubernetes.
-
When you're running apps behind a load balancer or API Gateway.
-
For development and testing environments.
Summary
Feature | Kestrel |
---|---|
Type | Web server for ASP.NET Core |
Cross-platform | ✅ Yes |
Default server | ✅ Yes (since ASP.NET Core 1.0) |
Reverse proxy support | ✅ Recommended in production |
HTTPS support | ✅ Yes |
Performance | 🔥 High-performance, async I/O |