部署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
本文采用 知识共享署名 4.0 国际许可协议 进行许可