I am trying to host an ASP.NET Core Web API in Digital Ocean Ubuntu 22.04 droplet with Nginx. It uses SQLite. When I run the dotnet build | dotnet run
commands everything works fine, Swagger opens, and the data is retrieved from the database.
However, after I publish using the dotnet publish
, create a service in /etc/systemd/system
and run it with sudo systemctl start myapi.service
, Swagger opens successfully, but any HTTP request results in "Error 500: internal service error".
The service file :
[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
2
Answers
Running the command
helped to see that the actual error was 'SQLite attempt to write a readonly database'. The solution was to change
User=www-data
toUser=root
in the service file.You have an internal server error, It’s not an error from the server config. The application return a 500. In terminal you can write:
to get the lasts errors of your app. Fix it, re-deploy.
You can also see what’s happening in the background by enabling logging. Here are two reference documents:
How can I log messages from an ASP.NET Core application to a specific file on Linux?.
Logging in .NET Core and ASP.NET Core.
Hope this can help you.