I am current using ASP.NET Core 2.0 behind nginx through HTTP requests in Ubuntu 16.
And I'd like to switch to Unix domain socket.
In my Program.cs I have:
var host = default(IWebHost);
var builder = new WebHostBuilder()
.UseKestrel(opt =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && settings.Config.ListenUnixSocket)
{
opt.ListenUnixSocket("/tmp/api.sock");
}
})
.Configure(app =>
{
app.Map("/health", b => b.Run(async context =>
{
context.Response.StatusCode = (int)HttpStatusCode.OK;
await context.Response.WriteAsync("Ok");
}));
});
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !settings.Config.ListenUnixSocket)
{
host = builder.UseUrls("http://0.0.0.0:5501").Build();
}
else
{
host = builder.Build();
}
host.Run();
And, at Nginx:
location /health {
#proxy_pass http://127.0.0.1:5501;
proxy_pass http://unix:/tmp/api.sock:/;
}
Running it using the default TCP socket works, but switching to Unix domain sockets, I got a 502 error.
Do I need any specific module at nginx? What I am doing wrong?