Skip to content

bdoor-b/deploy-aspnetcore-ubuntu-nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 

Repository files navigation

Deploy ASP.NET Core on Ubuntu with Nginx

This guide walks you through deploying an ASP.NET Core app on a Linux server using Nginx as a reverse proxy.


1. SSH into the Server

ssh username@your-server-ip

2. Install Required Packages

sudo apt update
sudo apt install -y wget

3. Install ASP.NET Core Runtime

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install -y aspnetcore-runtime-8.0  # based on your runtime version

Replace aspnetcore-runtime-8.0 with the correct runtime version if needed.


4. Publish Your App

cd "app path"
dotnet publish -c Release -o 
 

5. Create Deployment Directory on Server

sudo mkdir -p /var/www/myapp
sudo chown "username" /var/www/myapp

6. Upload Published Files (Using Your User Account)

scp -r "folder-path" username@your-server-ip:/var/www/myapp

Replace folder-path with your local publish directory.


7. Run the App to Test

cd /var/www/myapp/publish
dotnet app.dll --urls "http://0.0.0.0:5000"

Make sure to replace app.dll with your actual DLL name.


8. Install and Start Nginx

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

9. Configure Nginx Site

Create a new file:

sudo nano /etc/nginx/sites-available/app

Paste the following configuration:

server {
    listen 80;
    server_name your-server-ip;

    location / {
        proxy_pass         http://localhost: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;
    }
}

Replace your-server-ip with your actual server IP address.


10. Enable Nginx Site and Reload

sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
sudo systemctl reload nginx

11. Run the App in Background

cd /var/www/myapp/publish
nohup dotnet app.dll --urls "http://0.0.0.0:5000" &

nohup ensures the process continues running after logout. & runs the application as a background process.


Your ASP.NET Core app is now running behind Nginx and accessible at:

http://your-server-ip/

About

Simple step-by-step guide for deploying an ASP.NET Core app on Ubuntu with Nginx as a reverse proxy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published