如何在Arch Linux系统中配置.NET的dev-certs开发HTTPS证书?
Arch Linux下配置.NET Core HTTPS开发证书可行方案
前置清理(可选,建议操作)
如果之前生成过失效的.NET开发证书,先清理旧证书避免冲突:
dotnet dev-certs https --clean
步骤1:生成并导出.NET开发证书
- 生成基础自签本地开发证书
dotnet dev-certs https
- 导出证书为pfx格式,自行替换命令中的
自定义密码为你要设置的证书密码
dotnet dev-certs https -ep ~/.aspnet/https/aspnetapp.pfx -p 自定义密码
步骤2:导入证书到系统信任根
- 从pfx文件提取公钥crt证书,执行后输入上一步设置的自定义密码即可
openssl pkcs12 -in ~/.aspnet/https/aspnetapp.pfx -clcerts -nokeys -out localhost.crt
- 将crt证书复制到系统受信任CA目录
sudo cp localhost.crt /usr/local/share/ca-certificates/dotnet-dev-localhost.crt
- 更新系统CA信任缓存
sudo update-ca-trust
步骤3:配置项目使用证书
在你的ASP.NET Core项目的appsettings.Development.json中添加如下配置,替换你的用户名和自定义密码为实际内容:
{ "Kestrel": { "Endpoints": { "Https": { "Url": "https://localhost:5001", "Certificate": { "Path": "/home/你的用户名/.aspnet/https/aspnetapp.pfx", "Password": "自定义密码" } } } } }
浏览器适配说明
部分使用独立证书库的浏览器(如Firefox、Chrome)可能还需要手动将导出的localhost.crt导入到浏览器的「受信任的根证书颁发机构」列表中,即可正常识别localhost的HTTPS连接。
内容的提问来源于stack exchange,提问作者Daniel Kohn
相关产品推荐
相关产品推荐

