【发布时间】:2018-04-18 17:31:54
【问题描述】:
我目前在 Ubuntu 16 中通过 HTTP 请求在 nginx 后面使用 ASP.NET Core 2.0。
我想切换到 Unix 域套接字。
在我的 Program.cs 我有:
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();
并且,在 Nginx:
location /health {
#proxy_pass http://127.0.0.1:5501;
proxy_pass http://unix:/tmp/api.sock:/;
}
使用默认的 TCP 套接字运行它可以工作,但是切换到 Unix 域套接字,我得到了 502 错误。
我需要 nginx 的任何特定模块吗?我做错了什么?
【问题讨论】:
标签: nginx .net-core kestrel-http-server