Configure Kestrel listener to use configured IPs

This commit is contained in:
Joshua Boniface 2019-09-29 00:07:44 -04:00
parent 3249fbb715
commit cabb9aed31

View file

@ -615,12 +615,35 @@ namespace Emby.Server.Implementations
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseKestrel(options => .UseKestrel(options =>
{ {
var addresses = ServerConfigurationManager
.Configuration
.LocalNetworkAddresses
.Select(NormalizeConfiguredLocalAddress)
.Where(i => i != null)
.ToList();
if (addresses.Any())
{
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); options.ListenAnyIP(HttpPort);
if (EnableHttps && Certificate != null) if (EnableHttps && Certificate != null)
{ {
options.ListenAnyIP(HttpsPort, listenOptions => listenOptions.UseHttps(Certificate)); options.ListenAnyIP(HttpsPort, listenOptions => listenOptions.UseHttps(Certificate));
} }
}
}) })
.UseContentRoot(contentRoot) .UseContentRoot(contentRoot)
.ConfigureServices(services => .ConfigureServices(services =>