我目前正在设置一个新的自动部署,并想知道如何以编程方式在IIS 8上使用启用的SNI注册https绑定。网站已经存在,SSL证书已经安装。
powershell脚本中传递了以下参数:
假设SSL证书已经安装。
有谁可以帮我?
发布于 2014-10-22 16:33:35
如您所说,证书已经安装,应用程序池标识对私钥具有权限,那么您应该能够注册如下所示的新绑定:
New-WebBinding -Name $WebsiteName -Protocol "https" -Port 443 -IPAddress $IPAddress -HostHeader $HostHeader -SslFlags $sslFlags当然,您需要在运行此代码之前设置变量,但是这些变量应该是不言自明的。
在设置$sslFlags变量的值时,应根据下表进行设置:
0 No SNI
1 SNI Enabled
2 Non SNI binding which uses Central Certificate Store.
3 SNI binding which uses Central Certificate store在您的情况下,这应该设置为1,因为您没有使用中央证书存储。
完成SSL绑定之后,就需要将绑定与正确的证书关联起来。通过经验,我发现最简单的方法是使用netsh.exe命令。可以直接使用Powershell,但是,经过许多小时的调查和解决不同的问题,我发现netsh只是更可靠。
这里的语法取决于如何设置绑定,但是如果您使用SNI,那么您将需要以下语法:(不要担心appid,值是什么并不重要)
netsh http add sslcert hostnameport=$($HostHeader):$($Port) certhash=$Thumbprint appid='{4dc3e181-e14b-4a21-b022-59fc669b0914}' certstorename=MY此代码还要求设置变量。主机头应该是您的网站绑定到的DNS名称,端口很可能是443,变量$Thumbprint需要包含您将要使用的证书的拇指指纹或散列。您可以使用证书提供程序找到这一点,如下代码所示:
$Thumbprint = (Get-ChildItem -Path cert:\LocalMachine\My | Where-Object {$_.GetNameInfo("SimpleName",$false) -eq "my cert common name"}).Thumbprint希望这有帮助,如果你需要更多的帮助,然后更新问题。我在这方面做了很多工作。
发布于 2016-05-23 22:20:14
如果不想使用Netsh,还可以添加SNI绑定(设置了"Require名称指示“标志!)只使用Powershell。
下面是我为IIS8找到的最简单的方法:
# Parameters:
$WebsiteName = "Your Site Name" # this is the Sites name as displayed in IIS Manager
$port = 443 # SSL Port, when using SNI most likely the default port 443
$hostHeader = "www.example.com" # the domain / host-header this binding should listen for
$thumbprint = "AAABBBCCCDDDEEEFFF000111222333444555666" # the certificate thumbprint
# Commands:
New-Item -Path "IIS:\SslBindings\!$port!$hostHeader" -Thumbprint $thumbprint -SSLFlags 1
New-WebBinding -Name $WebsiteName -Protocol "https" -Port $port -HostHeader $hostHeader -SslFlags 1希望这对某人有帮助!
发布于 2016-12-06 16:28:41
实际上,绑定对象上有一个添加SSL的方法,它似乎比上述两个选项工作得更好
$Name = ''
$IP = ''
$HostHeader = ''
#ymmv here. if host header doesnt match subject name you need to adjust how you're getting the cert
$Cert = (gci cert:\LocalMachine\My) | ? { ( ($_.Subject | SLS '^(?:CN=)(.*?)(?=,)').matches.groups.value[-1]) -eq $HostHeader}
New-WebBinding -Name $Name -Protocol 'https' -Port 443 -IPAddress $IP -HostHeader $HostHeader -SslFlags 1
$NewBinding = get-webbinding -hostheader $HostHeader -protocol https
$NewBinding.AddSSLCertificate("$($cert.getcerthashstring())","MY")https://stackoverflow.com/questions/26485834
复制相似问题