End-to-End Deployment of ASP.
NET Core using Ubuntu (WSL)
Objective
The workflow mirrors real-world cloud deployment using Git, systemd, and Nginx.
Prerequisites
- Windows 10/11 with WSL2 enabled
- Ubuntu installed from Microsoft Store
- Basic knowledge of C#, .NET, and Linux commands
- GitHub account and sample [Link] Core repository
Architecture Overview
Browser → Nginx (Port 80) → systemd Service → [Link] Core (Kestrel) → Application
Code
Step 1: Update System and Install Required Packages
Commands:
sudo apt update
sudo apt upgrade -y
sudo apt install git nginx curl -y
Explanation:
Updates the system and installs Git for source control, Nginx as a reverse proxy, and curl for
testing APIs.
Step 2: Install .NET SDK and Runtime
Commands:
sudo apt install dotnet-sdk-8.0
sudo apt install dotnet-runtime-8.0
Explanation:
SDK is required for building the application, while runtime is sufficient for running it in
production.
Step 3: Clone Application from Git
Commands:
cd /var/www
sudo mkdir mydotnetapp
sudo chown -R $USER:$USER mydotnetapp
cd mydotnetapp
git clone <repository-url> .
Explanation:
Creates a standard deployment directory and pulls application code from GitHub.
Step 4: Build and Publish Application
Commands:
dotnet restore
dotnet build
dotnet publish -c Release -o out
Explanation:
Restores dependencies, compiles the code, and generates optimized binaries for
deployment.
Step 5: Test Application Locally
Commands:
cd out
dotnet [Link]
curl [Link]
Explanation:
Runs the application using Kestrel and verifies it is working before production hosting.
Step 6: Create systemd Service
Commands:
sudo nano /etc/systemd/system/[Link]
Explanation:
Creates a managed Linux service so the application runs continuously and restarts
automatically.
Step 7: Start and Enable Service
Commands:
sudo systemctl daemon-reload
sudo systemctl start mydotnetapp
sudo systemctl enable mydotnetapp
sudo systemctl status mydotnetapp
Explanation:
Loads service configuration and ensures the app runs on system startup.
Step 8: Configure Nginx Reverse Proxy
Commands:
sudo nano /etc/nginx/sites-available/mydotnetapp
sudo ln -s /etc/nginx/sites-available/mydotnetapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Explanation:
Exposes the .NET application on port 80 and forwards requests to Kestrel.
Step 9: Update Application Using Git (Redeployment Cycle)
Commands:
git pull
dotnet publish -c Release -o out
sudo systemctl restart mydotnetapp
Explanation:
Demonstrates real-world update workflow used in production systems.
Common Mistakes To Avoid
- Forgetting to test the app before configuring Nginx
- Incorrect file permissions causing service failures
- Not reloading systemd after editing service file
- Wrong port mapping between Nginx and [Link] Core
- Running app as root instead of www-data
- Editing Nginx config but forgetting to reload it
Expected Outcome
You will be able to access the [Link] Core application via browser using [Link]
and understand how enterprise-grade deployments work.