In ASP.NET Core 10, when ASPNETCORE_URLS, ASPNETCORE_HTTP_PORTS and a Kestrel:Endpoints section are all set, which addresses does Kestrel bind?
answer
- endpoints beat address lists
- Overriding address(es) warning
- urls beats HTTP_PORTS
- PreferHostingUrls flips the order
- HTTP_PORTS arrived in .NET 8
basics
~10 sOnly the Kestrel:Endpoints entries. Endpoints from configuration or ConfigureKestrel override the address list and Kestrel logs a warning; within that list, urls (ASPNETCORE_URLS, --urls) beats HTTP_PORTS/HTTPS_PORTS. PreferHostingUrls=true reverses the first rule.
solid answer
~40 sKestrel has two sources. **Endpoints** come from `Listen*` calls in `ConfigureKestrel` and from the `Kestrel:Endpoints` section; **addresses** come from `app.Urls` / `app.Run(url)`, the `urls` setting (`ASPNETCORE_URLS`, `--urls`) and the `HTTP_PORTS` / `HTTPS_PORTS` shorthand. If any endpoint exists, Kestrel binds the endpoints and logs a warning: "Overriding address(es) '...'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead." So in this case only `Kestrel:Endpoints` is bound. Inside the address list, an explicit `urls` value wins over `HTTP_PORTS`, again with a warning, and `app.Urls` entries replace both. Setting `preferHostingUrls` to `true` flips the first rule, making the addresses override the endpoints. With nothing at all, Kestrel binds `http://localhost:5000`.
code
json · 8 lines{
"Kestrel": {
"Endpoints": {
"Ingest": { "Url": "https://*:8443" },
"Health": { "Url": "http://*:8081" }
}
}
}go deeper
Remember that Kestrel:Endpoints and ConfigureKestrel endpoints beat ASPNETCORE_URLS, and that urls beats HTTP_PORTS.
Explain endpoints versus the address list, how app.Urls, urls and HTTP_PORTS fill that list, and what PreferHostingUrls changes.
Diagnose a probe failing on a port that is set in the environment by reading the override warnings, then settle each environment on a single binding mechanism.
Decide where binding is owned across platform and application teams, so container defaults, configuration files and code never fight over the port.
## Two kinds of binding input Kestrel distinguishes between **endpoints** and **addresses**, and the precedence question is really about how the two meet. - **Endpoints** are `ListenOptions` objects: everything you create with `Listen`, `ListenAnyIP`, `ListenLocalhost`, `ListenUnixSocket` or `ListenNamedPipe` inside `builder.WebHost.ConfigureKestrel`, plus every entry under the `Kestrel:Endpoints` configuration section. `WebApplication.CreateBuilder` loads that section through `KestrelServerOptions.Configure(...)` with reload-on-change switched on. - **Addresses** are plain URL strings in `IServerAddressesFeature.Addresses`. They come from `app.Urls.Add(...)` or `app.Run(url)`, from the `urls` configuration key (`ASPNETCORE_URLS`, `--urls`, or a `"urls"` entry in `appsettings.json`), and from the `HTTP_PORTS` / `HTTPS_PORTS` keys that .NET 8 introduced. ## How the address list is assembled Before Kestrel starts, the web host fills the address list in this order: 1. If code already put entries in `app.Urls` (directly or through `app.Run(url)`, which clears the list and adds its argument), those are used and configuration is not consulted. 2. Otherwise the `urls` key is read. If it has a value and `HTTP_PORTS` or `HTTPS_PORTS` is also set, the ports are ignored and the host logs a warning: "Overriding HTTP_PORTS '...' and HTTPS_PORTS '...'. Binding to values defined by URLS instead '...'." 3. Only when `urls` is empty are the ports expanded: `HTTP_PORTS=8080;8081` becomes `http://*:8080;http://*:8081`, and `HTTPS_PORTS` becomes `https://*:<port>` entries. ## How Kestrel combines addresses and endpoints Kestrel then picks a binding strategy: | Endpoints configured? | Addresses present? | `PreferHostingUrls` | Result | |---|---|---|---| | yes | yes | false (default) | endpoints bound, addresses ignored with the "Overriding address(es)" warning | | yes | yes | true | addresses bound, endpoints ignored with an "Overriding endpoints" message | | yes | no | either | endpoints bound | | no | yes | either | addresses bound | | no | no | either | `http://localhost:5000` | Applied to the question: `Kestrel:Endpoints` exists, so its entries are bound. `ASPNETCORE_URLS` beat `ASPNETCORE_HTTP_PORTS` while the list was being assembled, and then the whole list lost to the endpoints. Two warnings in the startup log tell the story. ## A worked example: the telemetry ingest ```json { "Kestrel": { "Endpoints": { "Ingest": { "Url": "https://*:8443" }, "Health": { "Url": "http://*:8081" } } } } ``` If the container platform also injects `ASPNETCORE_HTTP_PORTS=8080` and an operator adds `ASPNETCORE_URLS=http://+:5000`, the service still listens only on 8443 and 8081. A health probe pointed at 8080 or 5000 then fails, even though both variables are visibly set in the environment. The warnings are the clue. ## `PreferHostingUrls` `preferHostingUrls` is a host setting (`builder.WebHost.PreferHostingUrls(true)` or the `preferHostingUrls` configuration key). When it is true and addresses exist, Kestrel binds the addresses and ignores every configured endpoint, including the certificates and protocols those endpoints declared. It exists for hosts that must dictate the port from outside; it is rarely what an application wants. ## Settings that apply to every endpoint Precedence decides **which** endpoints exist; two hooks then shape all of them, whichever source created them: - `options.ConfigureEndpointDefaults(listen => ...)` and the `Kestrel:EndpointDefaults` section set shared values such as `Protocols` for every endpoint, including ones built from `urls` or `HTTP_PORTS`. - `options.ConfigureHttpsDefaults(https => ...)` sets shared TLS values (certificate, `SslProtocols`, `ClientCertificateMode`) for every HTTPS endpoint, including `https://` addresses from `ASPNETCORE_URLS`. So a team can keep binding in environment variables and still enforce, for example, a minimum TLS version from code. An `https://` address with no certificate anywhere still needs `Kestrel:Certificates:Default` or a development certificate, or startup fails. ## Practical rules - Pick **one** mechanism per environment. Endpoints in configuration are the richest (certificates, protocols, SNI per endpoint); `HTTP_PORTS` is the lightest and is what container images set. - Treat "Overriding address(es)" and "Overriding HTTP_PORTS" warnings as configuration bugs, not noise. - A URL's host part is not a filter: `http://*:8081` and `http://example.com:8081` bind the same interfaces. - `HTTPS_PORTS` (Kestrel binding) and `HTTPS_PORT` (the port the HTTPS redirection middleware redirects to) are different keys. ## Version notes `HTTP_PORTS` and `HTTPS_PORTS` arrived in .NET 8; before that, the only shorthand was `urls`. The precedence above is what ASP.NET Core 10.0 implements.
- What does app.Run("http://localhost:6000") do to ASPNETCORE_URLS?`Run(url)` clears `IServerAddressesFeature.Addresses` and adds its argument. Because the list is no longer empty, the host does not read `urls` or `HTTP_PORTS` at all, so the URL in code replaces them. Configured Kestrel endpoints still override it, and because the host reads `preferHostingUrls` only while it fills an empty address list, that switch does not rescue an address set in code.
- Why do container deployments often set ASPNETCORE_HTTP_PORTS rather than ASPNETCORE_URLS?A port list is all a container usually needs, and `HTTP_PORTS` expands to `http://*:<port>` without spelling out a scheme and wildcard host. Because it ranks below `urls`, an app or operator can still override it with a full URL when needed.
- How would you find out which addresses a running ASP.NET Core app actually bound?Read the `Now listening on:` lines the host logs at startup, or `app.Urls` after the app has started; Kestrel replaces the configured list with the addresses it really bound. Also look for the two override warnings, which say which input was discarded.
- ASPNETCORE_URLS always wins because environment variables override appsettings.json.
- Kestrel merges HTTP_PORTS and ASPNETCORE_URLS and binds both lists.
- HTTP_PORTS beats ASPNETCORE_URLS because it is the newer setting.
- The overriding-address warning is harmless startup noise.
- HTTPS_PORTS and HTTPS_PORT are two spellings of the same key.
Assumes ASP.NET Core 10; the HTTP_PORTS and HTTPS_PORTS keys exist since .NET 8 and rank below urls.