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

自作多情 提交于 2019-12-04 08:06:48

通过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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!