How to Deploy an ASP.NET Core Application on Linux

ASP.NET Core runs natively on Linux, letting you deploy .NET web applications on a standard Linux VPS behind Nginx — this guide covers the complete deployment pattern.

Prerequisites

  • .NET runtime installed (see How to Install .NET on Ubuntu & Debian)
  • Nginx installed for reverse proxying

Step 1 — Publish Your Application

dotnet publish -c Release -o /opt/myapp

Run this on your development machine or in CI/CD, then transfer the published output to your server.

Step 2 — Transfer to Your Server

scp -r /opt/myapp user@YOUR_SERVER_IP:/opt/myapp

Step 3 — Create a Dedicated System User

sudo useradd -r -s /bin/false aspnetapp

Step 4 — Set Ownership

sudo chown -R aspnetapp:aspnetapp /opt/myapp

Step 5 — Create a systemd Service

sudo nano /etc/systemd/system/myapp.service
[Unit]
Description=My ASP.NET Core Application
After=network.target

[Service]
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/dotnet /opt/myapp/MyApp.dll
Restart=always
RestartSec=10
User=aspnetapp
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=http://localhost:5000

[Install]
WantedBy=multi-user.target

Step 6 — Start and Enable the Service

sudo systemctl daemon-reload
sudo systemctl enable --now myapp

Step 7 — Verify It's Running

curl http://localhost:5000

Step 8 — Configure Nginx as a Reverse Proxy

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Step 9 — Add HTTPS

sudo certbot --nginx -d yourdomain.com

Configuring Environment-Specific Settings

Environment=ASPNETCORE_ENVIRONMENT=Production

Controls which appsettings.{Environment}.json file ASP.NET Core loads, following standard .NET configuration conventions.

Viewing Application Logs

sudo journalctl -u myapp -f

Handling Database Connection Strings Securely

See How to Manage Environment Variables and Secrets on a VPS — avoid hardcoding connection strings in appsettings.json committed to version control; use environment variables or a secrets manager instead.

Common Errors

502 Bad Gateway from Nginx — verify the ASP.NET Core application is actually running and listening on the port Nginx is configured to proxy to; check systemctl status myapp and the service logs.

Continue Reading

Browse more articles in Programming Languages & Runtimes.

  • deploy aspnet core linux, aspnet core nginx, dotnet systemd service, aspnet core production deployment
  • 0 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

How to Install PHP on Ubuntu & Debian (Complete Guide)

PHP powers a huge share of the web, including WordPress, Laravel, and Magento. This guide covers...

How to Install Node.js on Ubuntu & Debian (with NVM)

Node.js is a fast JavaScript runtime for building APIs, web applications, and backend services....

How to Install Python on Ubuntu & Debian

Python powers web frameworks like Django and Flask, automation scripts, and data applications....

How to Install Java (OpenJDK) on Ubuntu & Debian

Java powers enterprise applications, build tools like Maven and Gradle, and platforms like...

How to Install Composer for PHP Dependency Management

Composer is PHP's standard dependency manager, used by virtually every modern PHP framework...