Covers what a reverse proxy (Nginx, IIS, YARP, Azure Front Door, Application Gateway, Kubernetes ingress) does in front of Kestrel: TLS termination, routing, load balancing, buffering, limits and when you can expose Kestrel directly.
A reverse proxy sits between clients and Kestrel. Clients connect to the proxy; it forwards each request to one of your app instances over an internal connection. It typically does TLS termination (owns the certificate), routing by host or path, load balancing across instances, buffering of slow uploads and downloads, and enforces limits like body size, timeouts and rate limits.
Kestrel has been supported at the edge since ASP.NET Core 2.0, and in .NET 10 it serves HTTP/1.1, HTTP/2 and HTTP/3 (QUIC) with TLS 1.3, so a proxy is not mandatory. You add one when you need several apps on one IP and port 443, central certificates, a WAF, or zero-downtime instance swaps. In Azure you rarely run one yourself: App Service, Front Door, Application Gateway and Kubernetes ingress are reverse proxies. The trade-off is one more hop and one more set of timeouts, headers and error responses you must configure to agree with Kestrel.
"A reverse proxy is a server that accepts the client's connection on behalf of my application and forwards the request to Kestrel, which listens on an internal port. The client never talks to Kestrel directly. The proxy usually owns the TLS certificate and terminates HTTPS, routes requests by host name or path to the right backend, spreads load across several instances, and enforces limits: maximum body size, header size, timeouts and sometimes rate limits or a web application firewall.
In .NET terms, Kestrel is a perfectly capable edge server; Microsoft has supported exposing it to the internet since ASP.NET Core 2.0, and in .NET 10 it handles HTTP/1.1, HTTP/2 and HTTP/3 with sensible limits. So I don't add a proxy by habit. I add one when I need several sites behind one public IP and port 443, central certificate management, a WAF, or the ability to take instances out of rotation during a deploy. In practice in Azure the proxy is already there: App Service has front ends in front of your worker, Container Apps and AKS have ingress, and many teams put Front Door or Application Gateway at the edge.
The mistake I see is forgetting the app is now behind something. Kestrel sees the proxy's IP as the client and
httpas the scheme, so logs, rate limits and HTTPS redirects go wrong until you configure the forwarded headers middleware with the proxy as a known, trusted source. A proxy is cheap to add and easy to misconfigure; the second half is where the real work is."
| Job | What it means | Typical setting |
|---|---|---|
| TLS termination | Proxy holds the certificate, decrypts HTTPS | Certificate from Key Vault, TLS 1.2+ only |
| Routing | Host and path rules pick the backend | api.example.com/orders/* → orders cluster |
| Load balancing | Spreads requests across healthy instances | Round robin, least requests, health probes |
| Buffering | Absorbs slow clients so app threads are not held | Nginx proxy_buffering on |
| Limits | Body size, header size, timeouts | Nginx client_max_body_size 1m by default |
| Security edge | WAF, IP allow lists, DDoS protection | Front Door WAF, Application Gateway WAF |
| Compression and caching | Offload from the app | Front Door caching of static assets |
| Forward proxy | Reverse proxy | |
|---|---|---|
| Acts for | The client | The server |
| Client knows about it | Yes, configured in the client | No, it looks like the server |
| Example | Corporate outbound proxy | Nginx, YARP, Front Door |
| Situation | Proxy needed? |
|---|---|
| Single internal API on one VM, one port | No, Kestrel with HTTPS is fine |
| Several apps on one IP and port 443 | Yes, or Kestrel with SNI and a host-filtering layer |
| Need a WAF or central TLS policy | Yes, managed (Front Door / Application Gateway) |
| App Service, Container Apps, AKS | Already have one, configure it rather than add another |
A public API ran on three Container Apps replicas behind Azure Front Door. Front Door terminated TLS with a managed certificate and applied WAF rules; the app trusted only Front Door's X-Forwarded-* headers. Moving TLS and the WAF to the edge removed certificate renewals from the app team entirely and blocked roughly [2%] of traffic as bot noise before it reached Kestrel.
Checks that the candidate understands why a proxy sits in front of Kestrel, what it changes for the app, and that it is a choice rather than a rule.
Green flags
Red flags
Client ──TLS──▶ Reverse proxy ──HTTP or TLS──▶ Kestrel (:8080) ──▶ middleware ──▶ endpoint
443 terminates TLS, internal network
picks a backend,
adds X-Forwarded-*
There are two TCP connections: client to proxy, and proxy to app. Each has its own timeouts, keep-alive and size limits. Most proxy bugs come from the second connection being configured differently from the first.
Early ASP.NET Core (1.x) told you to always put IIS or Nginx in front. Since 2.0 Kestrel has request limits (MaxRequestBodySize about 28.6 MB by default, MaxRequestHeadersTotalSize 32 KB, minimum data rates to fight slow-loris clients) and is fuzzed and hardened. A proxy still helps with features Kestrel does not have: WAF, multi-app routing on one port, certificate automation, global anycast.
Behind a proxy, HttpContext.Connection.RemoteIpAddress is the proxy and Request.Scheme is http. The proxy adds:
X-Forwarded-For: 203.0.113.7
X-Forwarded-Proto: https
X-Forwarded-Host: api.example.com
UseForwardedHeaders rewrites the connection info from these headers, but only when the request comes from a trusted proxy (KnownProxies / KnownIPNetworks). Otherwise anyone could spoof their IP.
| Service | Layer | Scope |
|---|---|---|
| Azure Front Door | L7, global anycast | Internet edge, WAF, CDN |
| Application Gateway | L7, regional | VNet edge, WAF, path routing |
| Azure Load Balancer | L4 | TCP/UDP only, no HTTP awareness |
| App Service front ends | L7 | Built in, per app |
| Ingress / Gateway API controller | L7 | Inside AKS |
http://localhost:5000 and put Nginx in front on 8443 with a self-signed certificate. Log RemoteIpAddress and Scheme before and after adding UseForwardedHeaders.413; then raise client_max_body_size.Task.Delay(TimeSpan.FromSeconds(90)) endpoint behind Nginx and observe the 504 from the default 60-second proxy_read_timeout.A minimal API ready to run behind a reverse proxy: Kestrel on an internal port, forwarded headers (including the original host) trusted only from the proxy's network.
// Program.cs (.NET 10)
using System.Net;
using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor
| ForwardedHeaders.XForwardedProto
| ForwardedHeaders.XForwardedHost; // links and redirects use the public host
// Trust only the proxy subnet; never clear the lists to "trust everyone".
options.KnownIPNetworks.Add(IPNetwork.Parse("10.0.1.0/24"));
// Accept only the public host names, so a spoofed X-Forwarded-Host is ignored.
options.AllowedHosts = ["api.example.com"];
});
var app = builder.Build();
app.UseForwardedHeaders(); // first, so later middleware sees the real client, scheme and host
app.UseHttpsRedirection(); // now sees https from X-Forwarded-Proto, no redirect loop
app.MapGet("/whoami", (HttpContext ctx) => new WhoAmI(
ctx.Connection.RemoteIpAddress?.ToString(),
ctx.Request.Scheme,
ctx.Request.Host.Value));
app.Run();
public sealed record WhoAmI(string? ClientIp, string Scheme, string? Host);
The matching Nginx site, terminating TLS and forwarding to Kestrel:
server {
listen 443 ssl;
server_name api.example.com;
ssl_certificate /etc/ssl/api.crt;
ssl_certificate_key /etc/ssl/api.key;
ssl_protocols TLSv1.2 TLSv1.3;
client_max_body_size 10m; # default is 1m
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1; # default 1.0 breaks keep-alive and WebSockets
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
}
}
UseForwardedHeaders. Why it is wrong: Logs, rate limiting and audit trails record the proxy's IP, and UseHttpsRedirection loops because the scheme looks like http. Instead: Configure forwarded headers first in the pipeline.KnownProxies and KnownIPNetworks to make forwarded headers "just work". Why it is wrong: Any client can then spoof X-Forwarded-For and bypass IP-based rules or poison audit logs. Instead: Trust only the proxy's address or subnet.X-Forwarded-Host without AllowedHosts. Why it is wrong: A spoofed host ends up in password-reset links and redirects (host header injection). Instead: Restrict accepted hosts to your public names.application/problem+json cannot parse them, and the errors never reach app logs. Instead: Configure the proxy's error responses and alert on proxy-level 5xx separately.Access-Control-Allow-Origin headers make browsers reject the response. Instead: Own CORS in one place, usually the app's UseCors.Every proxy you add is another set of timeouts, size limits and header rules that must agree with Kestrel's. The best setups have exactly one layer per job: one edge (Front Door or Application Gateway) for TLS and WAF, one router (ingress or YARP) if you need path routing, and the app. I measure the hop's cost in Application Insights dependency timings; a well-placed regional proxy adds about 1 ms, a misplaced one in another region adds 20 ms or more.
The proxy also shapes capacity. Its health probes decide which instances get traffic, so probes must hit a readiness endpoint, not a deep database check, or one dependency blip drains every instance. Its connection reuse to the backend (HTTP/1.1 keep-alive or HTTP/2) matters as much as client-side protocol: HTTP/3 at the edge cuts handshake latency on mobile networks, but the hop to Kestrel usually stays HTTP/1.1 or HTTP/2. When scaling out, check the proxy's own limits (connections, SNAT ports, instance count) before blaming the app.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Kestrel direct | One internal service, simple TLS | Nothing extra | Need WAF or several sites on 443 |
| Nginx / IIS on the VM | Self-hosted VMs, legacy Windows hosting | Ops and patching | PaaS hosting already has a proxy |
| YARP | .NET team needs custom routing logic in C# | You run and scale it | Simple routing a managed service can do |
| Front Door / Application Gateway | Public apps in Azure needing WAF and TLS | Monthly service cost | Purely internal traffic |
CONNECT. HttpClient picks it up from system settings or HTTP_PROXY/HTTPS_PROXY/NO_PROXY.Behind a reverse proxy, the app sees the proxy's IP and often plain http. The proxy passes the originals in X-Forwarded-For and X-Forwarded-Proto, but ASP.NET Core only applies them via the ForwardedHeaders middleware, and by default only trusts proxies on loopback. So UseHttpsRedirection sees http, redirects to https, the proxy forwards as http again: a loop.
Fix: UseForwardedHeaders first, configured with the proxy's IPs or network in KnownProxies/known networks. Do not trust all sources, or clients can spoof their IP and scheme.
Kestrel is the default, cross-platform server built into ASP.NET Core and is fine to run directly, which is what you do in containers and on Linux. On Windows with IIS, the ASP.NET Core Module (ANCM) connects IIS to your app in one of two ways: in-process (the default), where the app runs inside the IIS worker process w3wp.exe using IISHttpServer instead of Kestrel and is fastest on IIS; or out-of-process, where IIS reverse-proxies to Kestrel running in a separate dotnet process. HTTP.sys is a Windows-only, kernel-mode server for when you need Windows authentication, port sharing or kernel caching without IIS. The trade-off: Kestrel is portable and simple, IIS gives Windows process management, and HTTP.sys gives Windows features without IIS.
TLS encrypts and authenticates the connection; HTTPS is HTTP over TLS. In ASP.NET Core, UseHttpsRedirection redirects plain-HTTP requests to HTTPS, and UseHsts adds the Strict-Transport-Security header so the browser refuses to use HTTP for that host for max-age (30 days by default), closing the first-request downgrade window after the first visit. Preload goes further: the domain is baked into browsers, so even the first visit is HTTPS — but it requires a year-long max-age, includeSubDomains, and is slow to undo.
For APIs, don't depend on redirects: non-browser clients ignore HSTS and may already have sent a token over HTTP, so refuse HTTP instead. Behind a proxy, run UseForwardedHeaders first or the app thinks every request is HTTP and loops.
Last updated 23 Nov 2026.