ASP.NET 酷睿 5.0 部署到 Ubuntu 20.04,出现 500 服务器错误和白屏



我正在尝试在 Ubuntu 5.0 服务器上运行 ASP.Net Core 20.04,并且在一切运行后出现白屏。FireFox中的网络选项卡给出了HTTP/1.1 500 Internal Server Error,所以在过去的两周里,我一直在互联网上搜索,试图在来到SO之前弄清楚这一点。

这是我现在配置所有内容的方式。

我在数字海洋上创建了一个Ubuntu 20.04 LTS x64液滴并安装了Nginx

以下是我安装Nginx并使其运行的步骤。

安装了所有需要的Microsoft包,如SDK和运行时

一切都已启动并运行,我可以看到正常的Nginx欢迎屏幕。创建了一个服务器块并添加了一个 Index.html 文件,也可以看到这一点。

然后我创建了一个目录,如下所示sudo mkdir -p /var/www/myDomainName还给我自己所需的权限

将我的存储库从 GitHub 克隆到新创建的dir,该具有对启动所需的转发标头中间件更改.cs如Microsoft文档中所述。

我运行dotnet build命令并得到以下内容。

/var/www/myDomain/src/Presentation/CTA.Web$ dotnet build
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.dll
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.Views.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.25

然后我运行dotnet publish命令并得到以下内容

/var/www/myDomain/src/Presentation/CTA.Web$ dotnet publish
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.dll
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.Views.dll
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/publish/

然后,我通过创建和编辑服务器块来配置服务器,其中显示以下内容:

server {
server_name myDomain.com www.myDomain.com;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myDomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myDomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.myDomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = myDomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

listen 80 ;
listen [::]:80 ;
#server_name myDomain.com www.myDomain.com;
return 404; # managed by Certbot

我也运行sudo nginx -s reload命令。

/etc/systemd/system,我创建了一个myDomain.service文件并添加了以下内容。

[Unit]
Description=Archery app
[Service]
WorkingDirectory=/var/www/myDomain
ExecStart=/usr/bin/dotnet /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/publish/CTA.Web.dll
Restart=always
RestartSec=10
SyslogIdentifier=archery
User=myUsername
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target

我运行 3 个命令

sudo systemctl enable myDomain.service    
sudo systemctl start myDomain.service    
sudo systemctl status myDomain.service

这是我得到的状态

myDomain.service - Archery app
Loaded: loaded (/etc/systemd/system/myDomain.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-12-12 02:38:49 UTC; 3 days ago
Main PID: 28005 (dotnet)
Tasks: 11 (limit: 1136)
Memory: 51.7M
CGroup: /system.slice/myDomain.service
└─28005 /usr/bin/dotnet /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/publish/CTA.Web.dll
Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, >Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, >Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Dec 15 02:28:27 eComArchery archery[28005]: info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Dec 15 02:28:27 eComArchery archery[28005]: Request finished HTTP/1.1 GET http://example.com/ - - - 500 0 - 32.0811ms

如果还有其他人想看,请告诉我。

您有内部服务器错误,这不是服务器配置的错误。应用程序返回 500。 在终端中你可以写

journalctl -u [YourServiceName].service --since '2021-MM-DD hh:mm:ss'

以获取应用的最后错误。修复它,重新部署。

请注意,您可能具有正确的服务器配置,因为内部服务器错误可能来自其他原因。

您必须通过启用日志来查看后台发生的情况。为此,请参阅如何在 linux 上的特定文件中记录来自核心应用程序的消息 asp.net?和登录 .NET Core 和 ASP.NET Core 以了解如何在 Linux 上启用它。 然后你可以找到主要问题。

相关内容

  • 没有找到相关文章

最新更新