Sam Hobbs

Sam Hobbs

  • 51
  • 29.3k
  • 2.1m

Hosting ASP.Net Core MVC using Nginx in Linux

Aug 7 2023 12:26 AM

I need to configure a website in Nginx that I can use a custom domain with, alongside other websites, not the default site.

I have a DigitalOcean Droplet (VM) with Nginx. I have a few HTML-only websites hosted there. Now I want to host an ASP.NET Core MVC application. I generated a MVC application (using dotnet new mvc) and pushed it to a GitHub repository and the application is built and deployed to the Droplet using a workflow. It is built and published using:

dotnet build project.csproj --configuration Release --no-restore
dotnet publish project.csproj -c Release -r linux-x64 --self-contained true

When I execute it (in the Droplet VM), it executes and I assume it works but of course the VM has no GUI so I am unable to browse to it that way.

The problem is that all the articles I find seem to try to cover all possibilities. I am not sure how much of that is relevant to me. There are two pieces; there is the ASP.Net in the MVC application and there is the Nginx configuration. I am connfused about what I need to do in the MVC application; must I modify the code that is generated? Normally when we create an application it works without modification. In this case, do I need to modify it to use it in Nginx?


Answers (2)