This guide explains how to deploy and host a .NET backend service and a frontend (React/Vue/Angular or static site) using systemd and Nginx on Ubuntu.
| Component | Path |
|---|---|
| Backend (systemd service) | /etc/systemd/system/mybackend.service |
| Backend published files (.dll) | /var/www/mybackend |
| Frontend files (HTML/CSS/JS) | /var/www/myfrontend |
| Nginx config | /etc/nginx/sites-available/myapp (linked to sites-enabled) |
dotnet publish -c Release -o /var/www/mybackend
.dll and related files into /var/www/mybackend.appsettings.json or launchSettings.json:"urls": "<http://localhost:5000>"
Create and edit the service file:
sudo nano /etc/systemd/system/mybackend.service
Paste the following:
[Unit]
Description=My .NET Backend Service
After=network.target
[Service]
WorkingDirectory=/var/www/mybackend
ExecStart=/usr/bin/dotnet /var/www/mybackend/MyBackend.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=mybackend
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target