itsource

Powershell - https 바인딩에 SSL 인증서 설정

mycopycode 2023. 10. 24. 21:19
반응형

Powershell - https 바인딩에 SSL 인증서 설정

PowerShell을 사용하여 자체 서명/로컬 인증서에 대한 IIS 사이트의 SSL 인증서를 설정하려고 합니다.

인증서를 만듭니다.

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

그런 다음 SSL 바인딩을 설정합니다.

get-item 
      cert:\LocalMachine\MY\$newCert.Thumbprint | 
      new-item -path IIS:\SslBindings\0.0.0.0!443

이 게시물에 나와 있는 것처럼: http://www.iis.net/learn/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in

여기에도 표시됨: Powershell IIS7 스냅인 SSL 인증서를 https 바인딩에 할당

저도 해봤습니다.

get-item 
      cert:\LocalMachine\MY\$newCert.Thumbprint | 
      new-item -path IIS:\SslBindings\*!443

사이트 바인딩 편집 대화상자에서 SSL 인증서 설정이 보이지 않습니다.

무슨 생각 있어요?

특정 사이트에 인증서를 할당해야 합니다.

Get-WebBinding cmdlet을 사용하여 사이트의 바인딩 정보를 검색하고 다음을 사용하여 SSL 인증서를 설정할 수 있습니다.AddSslCertificate함수:

$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")

답변을 사용할 때 "척 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

다른 파라미터도 설정할 수 있습니다(예:certstorename=MY). 자세한 내용은 HTTP Server API 페이지에서 확인하실 수 있습니다.

언급URL : https://stackoverflow.com/questions/32390097/powershell-set-ssl-certificate-on-https-binding

반응형