简体   繁体   English

在 NGINX 代理后面的 Ubuntu 上运行的 .NET Core 2.2 Web 应用程序中看不到错误原因

[英]Can't see cause of error in .NET Core 2.2 web app running on Ubuntu behind NGINX proxy

I have an Ubuntu server running NGINX as a reverse proxy to an ASP.NET Core 2.2 web API, and I am having trouble diagnosing a 500 server error I keep getting on requests to the API.我有一台运行 NGINX 作为反向代理到 ASP.NET Core 2.2 Web API 的 Ubuntu 服务器,我在诊断 500 服务器错误时遇到了麻烦,我不断收到对 API 的请求。

I have looked through all the logs I can see in /var/logs, the application logs which are set to trace, and the nginx error logs which are set to debug.我查看了在 /var/logs 中可以看到的所有日志、设置为跟踪的应用程序日志以及设置为调试的 nginx 错误日志。 However there is no clue about where the error lies.但是,没有任何关于错误所在的线索。

All requests to the API are failing with the same 500 response, except for one which is the IdentityServer authentication token endpoint which does work.对 API 的所有请求都失败并返回相同的 500 响应,除了 IdentityServer 身份验证令牌端点可以正常工作。 That is running in the same API.那是在同一个 API 中运行的。

I suspect the issue may be early in the request pipeline, before it comes into my controller actions.我怀疑这个问题可能在请求管道的早期,在它进入我的控制器操作之前。

There is a SQL Server database on the server but it is not being accessed for the particular requests I am trying so I am ruling that out.服务器上有一个 SQL Server 数据库,但我正在尝试的特定请求没有访问它,所以我排除了这一点。

My question is where else can I look to see what is going on?我的问题是我还能在哪里查看发生了什么? It must be something related to the application as that is the only thing that has changed, and another site running behind NGINX on the same machine is working fine so I'm not blaming the NGINX config.它必须与应用程序相关,因为这是唯一改变的东西,并且在同一台机器上运行在 NGINX 后面的另一个站点工作正常,所以我不会责怪 NGINX 配置。

When I revert the whole server to a backup before the deployment was done, everything runs fine.当我在部署完成之前将整个服务器恢复为备份时,一切运行正常。 The deployment of the application code breaks something but I just can't find out what or why.应用程序代码的部署破坏了一些东西,但我无法找出是什么或为什么。

The 500 error response is very plain without the usual headers. 500 错误响应非常简单,没有通常的标头。 NGINX has been configured to add a lot more response headers than this. NGINX 已被配置为添加比这更多的响应标头。

 HTTP/1.1 500 Internal Server Error Server: nginx Date: Thu, 05 Mar 2020 21:12:54 GMT Content-Length: 0 Connection: keep-alive Keep-Alive: timeout=30

The problem was with some code inside a constructor that was being called during application startup during dependency injection instantiation.问题在于构造函数中的一些代码在依赖注入实例化期间在应用程序启动期间被调用。

There was no problem while developing locally with 'dotnet run', but when publishing the files in Debug or Release mode, then it threw an exception.使用 'dotnet run' 在本地开发时没有问题,但是在 Debug 或 Release 模式下发布文件时,它抛出了异常。

The error was found after adding this line to the Startup.Configure method:将此行添加到 Startup.Configure 方法后发现错误:

 app.UseDeveloperExceptionPage();

This enabled me to see the error clearly straight away.这使我能够立即清楚地看到错误。 This error was not seen in any other logs, and the error only occurred when running published files, hence the difficulty in diagnosing the problem.此错误在其他任何日志中均未出现,且仅在运行已发布文件时出现,因此难以诊断问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载从 CLI 运行的 a.Net Core 3.0 Web 应用程序 - Can't Load a .Net Core 3.0 Web App Running From CLI App.Config中的默认代理导致.NET应用程序崩溃,没有错误 - Default proxy in App.Config cause .NET application to crash with no error 在ARM处理器(Raspberry Pi 3 B)/ Ubuntu(本机没有单声道)上运行ASP.Net Web App时出错 - Error in running ASP.Net Web App on ARM processor (Raspberry Pi 3 B) / Ubuntu (Natively without Mono) 在 .net 内核 2.2 中开发的 class 库可以被在 .net 内核 3.0 中编写的应用程序引用吗? - Can a class library developed in .net core 2.2 be referenced by an app written in .net core 3.0? .Net Core 2.2 Web API 405 - .Net Core 2.2 Web API 405 ASP.NET Core Angular应用程序无法在具有Nginx和Systemd的Ubuntu 16.04上运行 - ASP.NET Core Angular app fails to run on Ubuntu 16.04 with Nginx and Systemd 无法获取 IOptions 的值<t> , 在控制台应用程序 (.net Core 2.2.) 中值始终为 null</t> - Cannot get values for IOptions<T>, values always null in Console App (.net Core 2.2.) 无法运行.NET Core默认应用 - Can't run the .NET core default app 我的 ASP.NET Core 应用程序说它无法读取 web.config - My ASP.NET Core app says it can't read web.config Host.Net Core 2.2 web api 在安装了.Net框架的服务器上 - Host .Net Core 2.2 web api on Server with .Net framework installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM