How do I run more than one asp.net core application on Nginx server

April 29, 2018 322 views
Nginx Ubuntu 16.04

I want to run two or more asp.net core applications on the same server. But the ip and port they use are 127.0.0.1:5000.

2 Answers
mrkemaltas April 30, 2018
Accepted Answer

I found a solition ,

asp.net configration;

public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                 .UseUrls("http://localhost:5001/")    // We are here to work at a different port
                .Build();
    }

nginx configration

server_name  yourdomain.com ;
 location / {

                 proxy_pass http://localhost:5001; // Listening 5001 Port
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection keep-alive;
                 proxy_set_header Host $http_host;
                 proxy_cache_bypass $http_upgrade;

                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
        }

You can wrap them with Docker and configure them to listen different ports.

Read more about that
https://docs.microsoft.com/en-us/dotnet/core/docker/building-net-docker-images

Have another answer? Share your knowledge.