該賞金過期4天。此問題的答案有資格獲得 100聲望獎勵。 威士忌正在從信譽良好的來源尋找答案。
我正在嘗試在 Ubuntu 20.04 服務器上運行 ASP.Net Core 5.0,并且在一切運行后出現白屏。FireFox 中的網路選項卡給出了HTTP/1.1 500 Internal Server Error,所以我在過去的兩周里一直在互聯網上搜索,試圖在來到 SO 之前弄清楚這一點。
這是我現在配置所有內容的方式。
我Ubuntu 20.04 LTS x64在 Digital Ocean 上創建了一個Droplet 并安裝了Nginx.
以下是我安裝 Nginx 并讓它運行的步驟。
安裝了所有需要的 Microsoft 軟體包,如SDK 和 Runtime
一切正常,我可以看到正常的 Nginx 歡迎螢屏。創建了一個服務器塊并添加了一個 Index.html 檔案,并且可以看到它也很好。
然后我創建了一個像這樣的目錄sudo mkdir -p /var/www/myDomainName
也給我自己所需的權限
將我的存盤庫從 GitHub 克隆到新創建的存盤庫dir,其中將所需的轉發標頭中間件更改為 Microsoft 檔案中所述的 startup.cs。
我運行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
如果還有其他任何人想看,請告訴我。
uj5u.com熱心網友回復:
我已經在 ubuntu 18.04 和 20.04 上部署了 dotnet 核心應用程式,但使用了反向代理。
這是我的設定:
- 使用 systemd 和您的目標作業系統發布應用程式:
dotnet publish -c release -r ubuntu.20.04-x64 --self-contained
- 設定權限:
chmod 754 ./yourDotnetApp
- 在部署為服務之前檢查您的應用程式是否正在運行。
server2:~$ ./yourDotnetApp
Environment: Production Config: appsettings.json
// ...
或者
server2:~$ dotnet yourDotnetApp.dll
Environment: Production Config: appsettings.json
// ...
- 創建 yourDotnetApp.service 檔案并將其復制到 /etc/systemd/system 檔案夾。
[Unit]
Description=dotnet app service
After=network.target
[Service]
User=ubuntu # Replace your user here
WorkingDirectory=/path/to/your/app/
ExecStart=/path/to/your/app/yourDotnetApp
ExecStop=/bin/kill -s SIGKILL $MAINPID
SuccessExitStatus=SIGKILL
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 啟用服務。
sudo systemctl daemon-reload
sudo systemctl enable yourDotnetApp
sudo systemctl start yourDotnetApp
- 檢查一切是否按預期作業。
systemctl status yourDotnetApp.service
// Logs
journalctl -u yourDotnetApp.service -f -p 7
- 在 Nginx 上設定反向代理以訪問應用程式:
worker_processes 1;
events {
worker_connections 1024;
}
http {
# ...
server {
# ...
location / {
proxy_pass http://dotnet_kestrel/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ...
}
upstream dotnet_kestrel {
server localhost:5000;
server localhost:5001 down;
}
}
uj5u.com熱心網友回復:
請注意,您可能有正確的服務器配置,因為內部服務器錯誤可能來自其他原因。
您必須通過啟用日志來查看后臺發生的情況。所以,只要打開web.config檔案,改變stdoutLogEnabledto的值,true然后根據里面的值創建一個名稱為的檔案夾stdoutLogFile(例如,如果你有'.\logs\stdout',那么你需要創建一個名為logs的檔案夾),然后,make確保您已授予該檔案夾的寫入權限。重新啟動網路服務器并查看在日志檔案夾中創建的檔案,現在您可以找到主要問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/388355.html
標籤:C# asp.net-mvc asp.net核心 乌本图 nginx
上一篇:如何在不更改瀏覽器URL的情況下將流量路由到另一個域?
下一篇:sass的基本語法整理
