private void ConfigureKestrel(KestrelServerOptions options) { var ipEndPointList = new List <IPEndPointConfig>(); foreach (var site in _sites) { foreach (string host in site.Config.Hosts) { string[] hostData = host.Split(":", 2); string ipAddress = hostData[0]; int port = int.Parse(hostData[1]); if (TryGetIPEndPoint(ipEndPointList, ipAddress, port, out var endPoint)) { foreach (var sslConfig in site.Config.SslConfigs) { endPoint.AddCertificate(sslConfig.GetCertificate()); } } else { endPoint = new IPEndPointConfig(ipAddress, port); foreach (var sslConfig in site.Config.SslConfigs) { endPoint.AddCertificate(sslConfig.GetCertificate()); } ipEndPointList.Add(endPoint); } } } foreach (var endPoint in ipEndPointList) { options.Listen(endPoint.IPAddress, endPoint.Port, listenOptions => { if (endPoint.Certificates.Count > 0) { Logger.LogInfo($"Listening https on '{endPoint.IPAddress}:{endPoint.Port}'"); foreach (var certificate in endPoint.Certificates) { listenOptions.UseHttps(certificate); } } else { Logger.LogInfo($"Listening http on '{endPoint.IPAddress}:{endPoint.Port}'"); } }); } }
private IOptions <KestrelServerOptions> GetKestrelServerOptions(JObject config, IServiceProvider serviceProvider) { var endpoints = new List <string>(); var kestrelServerOptions = new KestrelServerOptions { ApplicationServices = serviceProvider }; foreach (var serverConfig in ServerConfigs) { if (serverConfig.UseSsl) { foreach (string endpoint in serverConfig.Endpoints) { if (endpoints.Contains(endpoint)) { continue; } endpoints.Add(endpoint); var certificate = new X509Certificate2(serverConfig.Certificate, serverConfig.CertificatePassword); kestrelServerOptions.Listen(IPEndPoint.Parse(endpoint), options => { options.UseHttps(certificate); }); } } else { foreach (string endpoint in serverConfig.Endpoints) { if (endpoints.Contains(endpoint)) { continue; } endpoints.Add(endpoint); kestrelServerOptions.Listen(IPEndPoint.Parse(endpoint)); } } } //kestrelServerOptions.Configure(); IOptions <KestrelServerOptions> optionFactory = Microsoft.Extensions.Options.Options.Create(kestrelServerOptions); return(optionFactory); }
internal KestrelConfigurationLoader(KestrelServerOptions options, IConfiguration configuration) { Options = options ?? throw new ArgumentNullException(nameof(options)); Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); ConfigurationReader = new ConfigurationReader(Configuration); }