To serve a .NET web app on an Ubuntu server in the simplest possible way, you can follow these steps:
- Install the .NET SDK on your Ubuntu server:
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-get update
sudo apt-get install -y dotnet-sdk-7.0
- Create a new directory for your app and navigate to it:
mkdir mywebapp
cd mywebapp
- Create a new ASP.NET Core web app:
dotnet new web
- Publish your app:
dotnet publish -c Release
- Navigate to the published files:
cd bin/Release/net7.0/publish
- Run your app:
dotnet mywebapp.dll
By default, this will start your web app on http://localhost:5000
and https://localhost:5001
.
To make your app accessible from outside the server, you can modify the Program.cs
file to listen on all interfaces:
app.Run("http://0.0.0.0:5000");
Then rebuild and republish your app.
This is the simplest way to serve a .NET web app on Ubuntu. However, for production use, you might want to consider using a reverse proxy like Nginx and setting up a service to keep your app running.
Would you like me to elaborate on any part of this process or explain how to set it up for production use?