我正在嘗試使用 Nginx 在 Digital Ocean Ubuntu 22.04 droplet 中托管 ASP.NET Core Web API。它使用 SQLite。當我運行dotnet build | dotnet run命令時,一切正常,Swagger 打開,并從資料庫中檢索資料。
但是,在我使用 發布后,在其中dotnet publish創建服務/etc/systemd/system并使用 運行它sudo systemctl start myapi.service,Swagger 成功打開,但任何 HTTP 請求都會導致“錯誤 500:內部服務錯誤”。
服務檔案:
[Unit]
Description=My API
[Service]
WorkingDirectory=/home/myAPI/bin/Debug/net6.0/publish
ExecStart=/usr/bin/dotnet /home/myAPI/bin/Debug/net6.0/publish/myAPI.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
uj5u.com熱心網友回復:
您有內部服務器錯誤,這不是服務器配置的錯誤。應用程式回傳 500。在終端中,您可以撰寫:
journalctl -u [YourServiceName].service --since '2021-MM-DD hh:mm:ss'
獲取您的應用程式的最后一個錯誤。修復它,重新部署。
您還可以通過啟用日志記錄來查看后臺發生的情況。這里有兩個參考檔案:
如何將來自 ASP.NET Core 應用程式的訊息記錄到 Linux 上的特定檔案?.
登錄 .NET Core 和 ASP.NET Core。
希望這可以幫到你。
uj5u.com熱心網友回復:
運行命令
journalctl -u [YourServiceName].service --since '2021-MM-DD hh:mm:ss'
幫助看到實際錯誤是“SQLite 嘗試撰寫只讀資料庫”。解決方案是在服務檔案中更改User=www-data為。User=root
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/511668.html
標籤:C#sqliteasp.net 核心nginx数字海洋
上一篇:NodeJS“同步”函式呼叫回傳[objectPromise]
下一篇:使用instr更新多行
