Nginx – .net core 3 with Nginx reverse proxy redirect to port 5001, but no page is loaded

netnginx

I'm trying to setup an ubuntu 18.04 droplet to run .Net Core 3.1 Web app. I'm following this tutorial.

So far I have the nginx working (or at least I can see the nginx welcome page) if I write the droplet IP in a browser.
I have created the /var/www/html/example.com folder with my .Net Core application inside and its working.
I have change my dns cache (on my local machine) to redirect example.com to my droplet IP.

But when I put example.com in the browser I get redirected to example.com:5001 with ERR_CONNECTION_REFUSED

The nginx access.log got this:

186.XXX.X.XX – – [03/May/2020:03:07:52 +0000] "GET / HTTP/1.1" 307 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"

This is my nginx configuration
/etc/nginx/sites-available/example.com

server {
   listen 80;
   server_name example.com *.example.com;

location / {
   proxy_pass http://localhost:5001;
   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;
   }
}

I'm pretty new in cloud systems and server setup so I'm kind of lost. I just want to get a server working, so I can upload some code and practice .Net Core coding. So any help would be nice!

Thank u in advice!

Best Answer

I figure it out what I was missing. I was running de app without specifing the port number in program.cs

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>().UseUrls(new[] { "http://0.0.0.0:5001" }); // now the Kestrel server will listen on port 5001!
            });
Related Topic