Skip to content

Instantly share code, notes, and snippets.

@bhatiavivek
Created August 7, 2024 06:03
Show Gist options
  • Save bhatiavivek/56894d7dd6d4e64738d1a41a7c47f070 to your computer and use it in GitHub Desktop.
Save bhatiavivek/56894d7dd6d4e64738d1a41a7c47f070 to your computer and use it in GitHub Desktop.

To serve a .NET web app on an Ubuntu server in the simplest possible way, you can follow these steps:

  1. 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
  1. Create a new directory for your app and navigate to it:
mkdir mywebapp
cd mywebapp
  1. Create a new ASP.NET Core web app:
dotnet new web
  1. Publish your app:
dotnet publish -c Release
  1. Navigate to the published files:
cd bin/Release/net7.0/publish
  1. 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment