📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What does a reverse proxy do in front of Kestrel? Explain TLS termination, routing, request buffering and limits, and whether a .NET 10 app still needs one now that Kestrel is a hardened, internet-facing server.

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.

Junior Theory Beginner aspnet-core devops kestrel load-balancing reverse-proxy tls-termination

🎯 Key points

  • Reverse proxy accepts client connections and forwards requests to Kestrel on an internal port
  • TLS termination: certificate and handshake handled at the proxy, plain HTTP or re-encrypted to the app
  • Routing by host and path to several apps or clusters, plus load balancing across healthy instances
  • Buffering and limits (body size, header size, timeouts, rate limits) protect app instances
  • Kestrel is supported at the edge (since 2.0; HTTP/3 and TLS 1.3 in .NET 10), so a proxy is a choice
  • Forwarded headers (For / Proto / Host) with UseForwardedHeaders, trusting only known proxies
  • Proxy-generated errors (413, 502, 504) and CORS preflights must be handled consistently with the app
  • In Azure the proxy is usually managed: App Service front ends, Front Door, Application Gateway, ingress

⏱ 30-second answer

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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 http as 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."


What a reverse proxy does

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 vs reverse proxy

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

When you can skip it

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

Production example

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.

🔍 What the interviewer is checking

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

  • Names TLS termination, routing, load balancing, buffering and limits
  • Knows Kestrel is supported at the edge and gives real reasons to add a proxy
  • Mentions forwarded headers and trusting only known proxies
  • Recognises managed proxies in Azure (Front Door, Application Gateway, ingress)

Red flags

  • "Kestrel is not production ready, always use IIS"
  • Confuses a reverse proxy with a forward proxy
  • No idea the app sees the proxy's IP and scheme

📚 Learn in depth

1. The request path

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.

2. TLS termination, passthrough and re-encryption

  • Termination: the proxy decrypts and forwards plain HTTP on a private network. Simplest; the app does not handle certificates.
  • Re-encryption (end-to-end TLS): the proxy decrypts, inspects, then opens a new TLS connection to the app. Needed when policy says traffic must be encrypted inside the network (common for Australian government workloads assessed against the ISM).
  • Passthrough: the proxy routes on SNI only and never decrypts. No WAF or header rewriting is possible.

3. Why Kestrel is safe at the edge now

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.

4. What the app must know

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.

5. Managed proxies in Azure

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

Try it yourself

  1. Run an API on Kestrel at http://localhost:5000 and put Nginx in front on 8443 with a self-signed certificate. Log RemoteIpAddress and Scheme before and after adding UseForwardedHeaders.
  2. Upload a 2 MB file through Nginx with default settings and see the 413; then raise client_max_body_size.
  3. Put a Task.Delay(TimeSpan.FromSeconds(90)) endpoint behind Nginx and observe the 504 from the default 60-second proxy_read_timeout.
  4. Compare a request trace in Application Insights with and without the proxy to see the extra hop's latency.

💻 Code

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;
    }
}

⚠ Common mistakes

  • Mistake: Believing Kestrel must always sit behind IIS or Nginx. Why it is wrong: That advice dates from ASP.NET Core 1.x; Kestrel has been supported at the edge since 2.0 and in .NET 10 serves HTTP/3 with TLS 1.3. Instead: Add a proxy for a reason (WAF, multi-site routing, certificates), not by default.
  • Mistake: Not calling 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.
  • Mistake: Clearing 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.
  • Mistake: Honouring 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.
  • Mistake: Leaving proxy defaults untouched. Why it is wrong: Nginx allows 1 MB bodies and waits 60 seconds by default, which breaks uploads and long requests. Instead: Set body size and timeouts to match the app's real limits.
  • Mistake: Letting the proxy return its own HTML error pages for 413, 502 and 504. Why it is wrong: API clients expecting 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.
  • Mistake: Adding CORS headers both at the proxy and in the app. Why it is wrong: Duplicate Access-Control-Allow-Origin headers make browsers reject the response. Instead: Own CORS in one place, usually the app's UseCors.
  • Mistake: Adding a second proxy inside App Service or Container Apps. Why it is wrong: The platform already has one; an extra Nginx adds latency and another place to break. Instead: Configure the platform's ingress.
  • Mistake: Terminating TLS and sending plain HTTP across an untrusted network. Why it is wrong: Traffic between proxy and app can be read. Instead: Keep the hop on a private network or re-encrypt.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions X-Forwarded-For or wrong client IPs behind the proxy Why: Checks they can debug forwarded headers and redirect loops safely, without trusting every proxy
    How to answer
    • A forward proxy sits in front of clients (corporate egress proxy): clients send requests through it to the internet. For HTTPS it tunnels with CONNECT. HttpClient picks it up from system settings or HTTP_PROXY/HTTPS_PROXY/NO_PROXY.
    • A reverse proxy sits in front of servers (nginx, Envoy, YARP, App Gateway, ingress): it terminates TLS, routes, load balances, caches and adds headers.

    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.

  2. When: Candidate mentions IIS in front of Kestrel Why: Checks they know in-process vs out-of-process hosting through the ASP.NET Core Module
    How to answer

    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.

  3. When: Candidate mentions TLS termination or HTTPS redirection Why: Checks how HTTPS redirection and HSTS behave when TLS ends at the proxy
    How to answer

    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.

↩ Usually asked after

More in Reverse Proxy and Gateway

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me