I have an open-source service application written in c#, running on .net 7, on Linux, which exposes an HTTP service, using Kestrel, to provide some monitoring endpoints for application state and important metrics for monitoring the application. It is configured to listen on a TCP endpoint, in appsettings.json, and that's great for when that's the desired configuration.
I also want to have Kestrel be able to listen on unix sockets, for reverse-proxy setups, among other reasons, at a specific path.
I can do it in code, fairly easily, but I would prefer to be able to configure it using the Kestrel section of my appsettings.json, as is done for the TCP socket listener, so end-users of the application can use standard configuration, rather than settings specific to just this application, that then get consumed in code to make kestrel listen at the desired socket path.
Documentation on how to do that seems to be non-existent, after many hours of scouring the net, including SO, Microsoft Learn, and numerous blogs.
Does anybody know how to configure Kestrel to listen on unix sockets at a specific socket path using appsettings.json?
Here's how the configuration is being given to Kestrel:
public static Task Main(string[] args)
{
// ...
WebApplicationBuilder serviceBuilder = WebApplication.CreateBuilder( );
// ...
serviceBuilder.WebHost
.UseKestrel( ConfigureKestrelOptions );
// ...
}
private static void ConfigureKestrelOptions( WebHostBuilderContext builderContext, KestrelServerOptions kestrelOptions )
{
kestrelOptions.Configure(_configurationRoot!.GetRequiredSection("Monitoring").GetSection("Kestrel") )
.Load( );
}
One attempted configuration was this:
{
"Monitoring": {
"Kestrel": {
"AllowedHosts": "*",
"Endpoints": {
"HttpMonitoringEndpoint": {
"Url": "http://*:60765"
},
"UnixSocketMonitoringEndpoint": {
"SocketPath": "/run/myapp/monitor.sock"
}
}
}
}
}
I have also tried putting the unix socket endpoint in a "UnixSocketEndpoints" and "UnixDomainSocketEndpoints" section, instead of "Endpoints." Those result in a unix socket being opened, but at a random temporary path, rather than the path specified.