Score:0

Hosting .NET Core Razor Application on Ubuntu 20.04 with NGINX

cn flag

I have started trying to self host some projects to get a better understanding of the Networking/Hosting principles and I have been having an issue with hosting a .NET CORE app in Visual Studio following the Razor MVVM pattern.

Main question is, is this even possible or does it need to be on Windows Server?

I initially wanted to create two websites off the same domain ie game.domain.com and api.domain.com.

I have one .net core API working so if I go to api.domain.com/swagger/index.html I can see my controllers and all that works fine. However, I thought since I wrote the Razor facing app with .net core as well, I could also host that on the same Ubuntu server with NGINX.

So right now I have two nginx sites setup in folders

  • /var/www/api.domain.com/html
  • /var/www/twerkle.domain.com/html

Inside each of the html folders, I have a basic index file that gets served as a dummy landing page just to prove I can get to either site through the public IP and it routes it via NGINX. However, I can not seem to get the twerkle.domain.com page to show the main razor .cshtml page.

I followed this link to get the Services setup so it runs the dotnet on the folder's and have the two services running and listing.

Ubuntu Services running

Every tutorial or documentation that I have seen has mainly been in regards to .net core apps utilizing them as an api.

Here shows the basic index.html landing page being displayed. TwerklePage

Score:0
cn flag

I revisted the /etc/nginx/nginx.conf file and I noticed I had two entries for the game.domain.com address. I modified it so there was just one. I also added the additional /wwwroot directory as well as index index.cshtml lines. And I noticed my publish folder on the server just had the main .DLLs and an emtpty wwwroot folder, so I moved the .cshtml files over as well. Now I can go to twerkle.domain.com and be served the application I was expecting.

    server {
      listen        80;
      server_name  twerkle.domain.com;
      root /var/www/twerkle.domain.com/html/wwwroot; <-- /wwwoot was added
      index index.cshtml; <-- this line was added
      location / {
        try_files $uri $uri/ $uri.cshtml = 404;
        proxy_pass         http://localhost:5002;
        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;
      }
    }
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.