Loading

部署asp.net core Kestrel 支持https 使用openssl自签ssl证书

通过openssl生成证书

openssl req -newkey rsa:2048 -nodes -keyout my.key -x509 -days 365 -out my.cer
openssl pkcs12 -export -in my.cer -inkey my.key -out my.pfx

将pfx设置为Embedded resource

program 添加代码

         public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseKestrel(opt => opt.ConfigureHttpsDefaults(x => x.ServerCertificate = Certificate.Get()));
                    webBuilder.UseStartup<Startup>();
                });        

源码:
https://github.com/wswind/Support-SSL-Sample.git

参考:
https://www.cnblogs.com/edisonchou/p/identityserver4_foundation_and_quickstart_01.html
https://www.cnblogs.com/linezero/p/aspnetcorehttps.html
https://github.com/dotnet-architecture/eShopOnContainers
https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs

posted @ 2019-11-13 10:46  wswind  阅读(1092)  评论(0编辑  收藏  举报