From cabb9aed3142773ab3bec4627b2aec3dc470f02e Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 29 Sep 2019 00:07:44 -0400 Subject: [PATCH 1/2] Configure Kestrel listener to use configured IPs --- .../ApplicationHost.cs | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 1d0293a5f3..5719c5e46f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -615,11 +615,34 @@ namespace Emby.Server.Implementations var host = new WebHostBuilder() .UseKestrel(options => { - options.ListenAnyIP(HttpPort); - - if (EnableHttps && Certificate != null) + var addresses = ServerConfigurationManager + .Configuration + .LocalNetworkAddresses + .Select(NormalizeConfiguredLocalAddress) + .Where(i => i != null) + .ToList(); + if (addresses.Any()) { - options.ListenAnyIP(HttpsPort, listenOptions => listenOptions.UseHttps(Certificate)); + foreach (var address in addresses) + { + Logger.LogInformation("Kestrel listening on {ipaddr}", address); + options.Listen(address, HttpPort); + + if (EnableHttps && Certificate != null) + { + options.Listen(address, HttpsPort, listenOptions => listenOptions.UseHttps(Certificate)); + } + } + } + else + { + Logger.LogInformation("Kestrel listening on all interfaces"); + options.ListenAnyIP(HttpPort); + + if (EnableHttps && Certificate != null) + { + options.ListenAnyIP(HttpsPort, listenOptions => listenOptions.UseHttps(Certificate)); + } } }) .UseContentRoot(contentRoot) From 387192610f5aca62e691dfe2dfed92a5889c6cd7 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 29 Sep 2019 17:17:19 -0400 Subject: [PATCH 2/2] Handle Kestrel startup failures with a nice error --- Emby.Server.Implementations/ApplicationHost.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 5719c5e46f..d22f2be817 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -663,7 +663,15 @@ namespace Emby.Server.Implementations }) .Build(); - await host.StartAsync().ConfigureAwait(false); + try + { + await host.StartAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + Logger.LogError("Kestrel failed to start! This is most likely due to an invalid address or port bind - correct your bind configuration in system.xml and try again."); + throw; + } } private async Task ExecuteWebsocketHandlerAsync(HttpContext context, Func next)