Tuesday, February 17, 2026

Deploying ASP.NET MVC app on Ubuntu

.NET 10 MVC Deployment on Ubuntu with Nginx, systemd, PostgreSQL & Cloudflare

Architecture:

Browser → Cloudflare (Flexible SSL)
            ↓
         Nginx (Port 80)
            ↓
       ASP.NET Core (localhost:5000)
            ↓
         PostgreSQL

1️⃣ Publish the .NET 10 MVC App (Local Machine)

dotnet restore
dotnet publish -c Release -o .\publish
Compress-Archive -Path .\publish\* -DestinationPath .\publish.zip -Force
Upload publish.zip to the Ubuntu server.

2️⃣ Install Nginx

sudo apt update
sudo apt install -y nginx
sudo systemctl enable --now nginx

3️⃣ Install .NET 10 ASP.NET Runtime

sudo apt install -y wget apt-transport-https
wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

sudo apt update
sudo apt install -y aspnetcore-runtime-10.0
Verify:
dotnet --list-runtimes

4️⃣ Install and Configure PostgreSQL

sudo apt install -y postgresql postgresql-contrib postgresql-client
sudo systemctl enable --now postgresql
Create database and user:
sudo -u postgres psql

CREATE DATABASE "DelhiKitchenDB";
CREATE USER delhikitchendbuser WITH PASSWORD 'YOUR_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE "DelhiKitchenDB" TO delhikitchendbuser;
\q
Grant schema permissions:
sudo -u postgres psql -d "DelhiKitchenDB"

GRANT USAGE, CREATE ON SCHEMA public TO delhikitchendbuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO delhikitchendbuser;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO delhikitchendbuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO delhikitchendbuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON SEQUENCES TO delhikitchendbuser;
\q

5️⃣ Deploy Application Files

sudo mkdir -p /var/www/mydelhikitchen.com
sudo unzip publish.zip -d /var/www/mydelhikitchen.com
sudo chown -R www-data:www-data /var/www/mydelhikitchen.com
sudo chmod -R 755 /var/www/mydelhikitchen.com

6️⃣ Configure Upload Folder Permissions

sudo mkdir -p /var/www/mydelhikitchen.com/wwwroot/images
sudo chown -R www-data:www-data /var/www/mydelhikitchen.com/wwwroot/images
sudo chmod -R 775 /var/www/mydelhikitchen.com/wwwroot/images

7️⃣ Ensure Migrations Run

Add in Program.cs after builder.Build():

using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
    db.Database.Migrate();
}

using (var scope = app.Services.CreateScope())
{
    var services = scope.ServiceProvider;
    await DbSeeder.SeedAsync(services);
}
Ensure middleware:
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

8️⃣ Create systemd Service

sudo nano /etc/systemd/system/mydelhikitchen.service
[Unit]
Description=MyDelhiKitchen ASP.NET MVC App
After=network.target

[Service]
WorkingDirectory=/var/www/mydelhikitchen.com
ExecStart=/usr/bin/dotnet /var/www/mydelhikitchen.com/EcommerceStore.dll
Restart=always
RestartSec=5
User=www-data

Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://localhost:5000
Environment=ConnectionStrings__DefaultConnection=Host=localhost;Port=5432;Database=DelhiKitchenDB;Username=delhikitchendbuser;Password=YOUR_PASSWORD

[Install]
WantedBy=multi-user.target
Enable:
sudo systemctl daemon-reload
sudo systemctl enable --now mydelhikitchen.service

9️⃣ Configure Nginx

sudo nano /etc/nginx/sites-available/mydelhikitchen.com.conf
server {
    listen 80;
    server_name mydelhikitchen.com www.mydelhikitchen.com;

    location /images/ {
        alias /var/www/mydelhikitchen.com/wwwroot/images/;
        try_files $uri =404;
    }

    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
Enable and reload:
sudo ln -s /etc/nginx/sites-available/mydelhikitchen.com.conf /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

🔟 Cloudflare DNS (Flexible SSL)

  • A record → server public IP
  • www CNAME → root domain
  • SSL mode → Flexible
  • Purge cache after major updates if needed

Deployment Complete ✅

Your .NET 10 MVC application is now running on Ubuntu with:

  • systemd process management
  • Nginx reverse proxy
  • PostgreSQL database
  • Upload image support
  • Cloudflare DNS + Flexible SSL

Deploying ASP.NET MVC app on Ubuntu

.NET 10 MVC Deployment on Ubuntu with Nginx, systemd, PostgreSQL & Cloudflare Architecture: Browser → Cloudflare (Flexible SSL)...