Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Can not access service when running as Kestrel in Debian #8120


User avatar
0
npdevs created

Hi,

When we run web-host in Debian, the service starts but is not accessible from the outside of the box.

In the meantime the service can be successfully accessed inside the box, e.g. with the command: curl -L http://localhost:5000 No firewall involved, service just binds to the localhost network interface instead of external interface.

We use ASP.NET CORE & Angular version of template (two separate VS solutions), template version 7.2.3. We running as Kestrel on Debian 10 and .NET Core 2.2.7 with simple command: dotnet <myproject>.Web.Host.dll Binaries were published from Visual Studio 2017 using simple publishing to a folder ("File System" publish method).

We have tried to put Kestrel configuration options in appsettings.json Something similar to config example described here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2#listenoptionsusehttps-1

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://*:5555"
      }
    }
  }
}

But looks like service does not use this configuration.

  1. How can we configure service to bind network interface other than localhost, e.g. bind to http://*:5000
  2. How can we configure service to listen on different port, e.g. http://localhost:5555 or better http://*:5555
  3. How can we make other Kestrel options in appsettings.json be respected by the service, as described in https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2#kestrel-options-1

Thanks!


2 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team
    public class Program
    {
       public static void Main(string[] args)
       {
          CurrentDirectoryHelpers.SetCurrentDirectory();
          CreateWebHostBuilder(args).Build().Run();
       }
    
       public static IWebHostBuilder CreateWebHostBuilder(string[] args)
       {
          return new WebHostBuilder()
             .ConfigureAppConfiguration((hostingContext, config) =>
             {
                var env = hostingContext.HostingEnvironment;
    
                config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                   .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
    
                if (env.IsDevelopment())
                {
                   config.AddUserSecrets(typeof(Program).Assembly, optional: true);
                }
    
                config.AddEnvironmentVariables();
    
                if (args != null)
                {
                   config.AddCommandLine(args);
                }
             })
             .UseKestrel((builderContext, options) =>
             {
                options.Configure(builderContext.Configuration.GetSection("Kestrel"));
             })
             .UseContentRoot(Directory.GetCurrentDirectory())
             .UseIIS()
             .UseIISIntegration()
             .UseStartup<Startup>();
       }
    }
    

  • User Avatar
    0
    npdevs created

    It works. Thank you!