c# - 使用 Nginx 在 Linux 上托管 ASP.NET Core - 在 LAN 上无法访问站点
问题描述
我正在尝试在 Linux 上访问 ASP .net Core 3 Web API(本例为树莓派)。
该 API 在 localhost 中完美运行,无论是在我的笔记本电脑上还是在本地访问时在 pi 上。但是,当我尝试让它在ASP DOCS之后的计划中可用时,它不起作用。
如果我让 dotnet 应用程序运行,我会得到以下信息:
“此站点无法访问 192.168.1.50 拒绝连接。尝试:
检查连接 检查代理和防火墙 ERR_CONNECTION_REFUSED" "
如果 dotnet 应用程序未运行并且我尝试访问 Nginx 服务器,我会得到以下信息:
502错误的网关
NGINX 似乎正在做一些事情,因为运行它的应用程序将它转发到正确的端口 5001
我的程序.cs:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
我的启动.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var con = new ConnectionStrings();
Configuration.Bind("ConnectionStrings", con);
services.AddSingleton(con);
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
来自 Linux 的 dotnet:
dotnet Fan.dll
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /home/pi/WebApp
Linux Nginx 状态/配置:
解决方案
推荐阅读
- json - 通过 Ansible playbook 确保配置文件(用于 Atom IDE)中有一些字段
- sapui5 - SAP Fiori 性能测试
- android - 如何使用相机捕获图像并将其保存在服务器上?
- python - 在 python/pandas 中将年/月转换为年/月/日
- java - 通过邻接表的前序遍历
- arrays - Numpy for 循环运行时间太长
- laravel - Laravel 5.4 Handler.php 从 Ajax 调用重定向
- jquery - 带有外部链接的 Fancybox 内嵌图像
- powershell - PS 调用命令和 writeallbyes
- python - spaCy NLP word.pos 返回数字而不是 POS 标签