Hosting .NET Backend + Frontend with Nginx on Ubuntu

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.


📂 Project Structure

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)

1️⃣ Backend Setup (.NET)

Step 1: Publish the .NET backend

dotnet publish -c Release -o /var/www/mybackend

"urls": "<http://localhost:5000>"


Step 2: Create a systemd service

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


Step 3: Enable and start the service