Created
August 7, 2024 06:03
-
-
Save bhatiavivek/56894d7dd6d4e64738d1a41a7c47f070 to your computer and use it in GitHub Desktop.
Revisions
-
bhatiavivek created this gist
Aug 7, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ 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: ```bash 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 ``` 2. Create a new directory for your app and navigate to it: ```bash mkdir mywebapp cd mywebapp ``` 3. Create a new ASP.NET Core web app: ```bash dotnet new web ``` 4. Publish your app: ```bash dotnet publish -c Release ``` 5. Navigate to the published files: ```bash cd bin/Release/net7.0/publish ``` 6. Run your app: ```bash 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: ```csharp 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?