簡體   English   中英

Powershell - 在 https 綁定上設置 SSL 證書

[英]Powershell - Set SSL Certificate on https Binding

我正在嘗試使用 PowerShell 在 IIS 站點上為自簽名\/本地證書設置 SSL 證書。

我創建證書:

$newCert = 
       New-SelfSignedCertificate 
       -DnsName www.mywebsite.ru 
       -CertStoreLocation cert:\LocalMachine\My

您必須將證書分配給特定站點。

您可以使用Get-WebBinding cmdlet 檢索站點的綁定信息,並使用AddSslCertificate函數設置 SSL 證書:

$siteName = 'mywebsite'
$dnsName = 'www.mywebsite.ru'

# create the ssl certificate
$newCert = New-SelfSignedCertificate -DnsName $dnsName -CertStoreLocation cert:\LocalMachine\My

# get the web binding of the site
$binding = Get-WebBinding -Name $siteName -Protocol "https"

# set the ssl certificate
$binding.AddSslCertificate($newCert.GetCertHashString(), "my")

我在使用答案時遇到了與“Chuck D”相同的錯誤,我發現需要一個額外的步驟:

在綁定到添加到 IIS 網站綁定之前,SSL 證書需要在證書存儲中。 這可以使用以下命令在 powershell 中完成:

Import-PfxCertificate -FilePath "C:\path to certificate file\certificate.pfx" -CertStoreLocation "Cert:\LocalMachine\My"

AddSslCertificate 方法並非隨處可用。 我通過使用 Netsh 找到了不同的解決方案。

$iisCert = Get-ChildItem -Path "Cert:\LocalMachine\MY" `
| Where-Object { $_.FriendlyName -eq "IIS Express Development Certificate" } `
| Select-Object -First 1

$applicationId = [Guid]::NewGuid().ToString("B") 

netsh http add sslcert ipport=0.0.0.0:443 certhash=$($iisCert.Thumbprint) appid=$applicationId

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM