Web server
A web server is a program that accepts connections, reads HTTP requests, and sends answers back. In ASP.NET Core, the Kestrel server takes on this task, alone on the network or behind a reverse proxy.
A web server is a program that accepts connections, reads HTTP requests, and sends answers back, such as an HTML page, a file, or JSON. The word means the software. In everyday language, the computer it runs on is called that too, but that is the second meaning of the word.
The web server in ASP.NET Core
Every ASP.NET Core application brings its web server along. That is Kestrel, a cross-platform server for Windows, Linux, and macOS. It is the default in the project templates, supports HTTP/1.1, HTTP/2, and HTTP/3 as well as WebSockets, and passes every request on to your application: to minimal APIs, Blazor, SignalR, or gRPC. On Windows, there are also the IIS HTTP Server and HTTP.sys.
Your application is therefore a console program that contains a server. Whoever starts dotnet run also starts the web server. The response headers then say Server: Kestrel.
With or without a reverse proxy
Microsoft supports two setups: Kestrel alone on the internet, or behind a reverse proxy such as IIS, Nginx, Apache, or YARP. A reverse proxy accepts requests from outside and forwards them to Kestrel. It can reduce the public attack surface, manage the HTTPS certificate, distribute load, and fit better into the existing infrastructure.
This has consequences for the code. Behind a proxy, the application at first sees only the proxy's address and protocol, not the visitor's. The middleware for forwarded headers (UseForwardedHeaders) restores the scheme and the address. Without it, redirects and cookies with the Secure flag easily go wrong. In Azure, such a proxy usually stands in front of your application: in Container Apps it is the ingress, and Azure Front Door can stand in front of that.
How it differs
- Web server and application server: In ASP.NET Core, the line blurs. Kestrel accepts the request and your application answers it, both in the same process.
- Web server and hosting: The server is the software; hosting is the place where it runs. For the place, see cloud computing.
- Static files: Kestrel can serve them too. For very heavy load or caching, a proxy or a content delivery network is often put in front.
- Kestrel is no shield against denial-of-service attacks. Microsoft explicitly points out that network protection in front of it is needed for that.
An example from the Kladde
The Kladde's first web API answers GET requests with JSON. In the course, you see the header Server: Kestrel in the answer and learn why something usually stands in front of it in operation. When the Kladde is delivered to Azure Container Apps, the ingress takes on this role and accepts HTTPS. So that the application knows that the request came over HTTPS, it evaluates the forwarded headers; the lesson on delivery switches this on with the environment variable ASPNETCORE_FORWARDEDHEADERS_ENABLED.
In the course
You get to know the web server in K2: module 2.1 has How the web talks: HTTP, and module 2.3 The first web API, where Kestrel appears. Proxies and load balancers are covered in K3, module 3.0, in the lesson Proxies and load balancers.