This guide walks you through deploying an ASP.NET Core app on a Linux server using Nginx as a reverse proxy.
ssh username@your-server-ip
sudo apt update
sudo apt install -y wget
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.
cd "app path"
dotnet publish -c Release -o
sudo mkdir -p /var/www/myapp
sudo chown "username" /var/www/myapp
scp -r "folder-path" username@your-server-ip:/var/www/myapp
Replace
folder-path
with your local publish directory.
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.
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
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.
sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
sudo systemctl reload nginx
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/