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
- How to Install .NET on Ubuntu & Debian
- How to Manage Environment Variables and Secrets on a VPS
- How to Configure Nginx as a Reverse Proxy for Node.js/Docker Apps
Browse more articles in Programming Languages & Runtimes.