最后我弄清楚了这个问题。问题是开发人员 ssl 证书是与 dotnet SDK 一起安装的,名称为 localhost。对于 Ubuntu,证书位于 /home/{用户名} /.dotnet/corefx/cryptography/x509stores/my
Kestrel 只是在执行用户的主目录中搜索,该目录不存在“www-data”,因此它无法找到开发证书。因此它不会绑定到默认的 https 端口。
为了让它工作,我首先在 PEM 中转换了我现有的证书(.crt) 格式转换为 PKCS12 (.pkf)使用 OpenSSL。下面是命令。
sudo openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile more.crt
然后我需要使用 appsettings.json 文件将此证书指定给 Kestrel 服务器。下面是文件现在的样子:
{
"ConnectionStrings": {
"PostgresConnection": "Host=localhost; Database=postgres; Username=postgres; Password=xyz123"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"Kestrel": {
"Endpoints": {
"HTTPS": {
"Url": "https://localhost:5001",
"Certificate": {
"Path": "/etc/ssl/certs/<certificate.pfx>",
"Password": "xyz123"
}
}
}
}
}
然后您需要将 www-data 用户添加到 ssl-certs 组。下面是命令行:
sudo usermod -aG ssl-cert www-data