如何从命令提示符向IIS7站点分配SSL证书

如何从命令提示符向IIS7站点分配SSL证书,iis,iis-7,ssl,ssl-certificate,appcmd,Iis,Iis 7,Ssl,Ssl Certificate,Appcmd,您能告诉我是否可以使用APPCMD应用程序将SSL证书分配给IIS7中的网站吗 我熟悉设置HTTPS绑定的命令 appcmd set site /site.name:"A Site" /+bindings.[protocol='https',bindingInformation='*:443:www.mysite.com'] 以及如何获得当前映射 %windir%\system32\inetsrv\Appcmd 但是似乎找不到任何方法将站点映射到证书(例如证书哈希)答案是使用NETSH。 比

您能告诉我是否可以使用APPCMD应用程序将SSL证书分配给IIS7中的网站吗

我熟悉设置HTTPS绑定的命令

appcmd set site /site.name:"A Site" /+bindings.[protocol='https',bindingInformation='*:443:www.mysite.com']
以及如何获得当前映射

%windir%\system32\inetsrv\Appcmd

但是似乎找不到任何方法将站点映射到证书(例如证书哈希)

答案是使用NETSH。 比如说

netsh http add sslcert ipport=0.0.0.0:443 certhash='baf9926b466e8565217b5e6287c97973dcd54874' appid='{ab3c58f7-8316-42e3-bc6e-771d4ce4b201}'

这对我帮助很大:Sukesh Ashok Kumar提供了一个简单的指南,从命令行为IIS设置SSL。包括使用
certutil
/
makecert
导入/生成证书


编辑:如果原始URL已关闭,它仍然可用。

@David和@orip将其设置正确

但是,我确实想提到,示例(0.0.0.0:443)中指定的ipport参数是MSDN所称的“未指定地址(IPv4:0.0.0.0或IPv6:[::])”

我去查了一下,所以我想我应该在这里记录下来,这样可以节省别人的时间。本文的重点是SQL Server,但信息仍然相关:


使用PowerShell和WebAdministration模块,您可以执行以下操作,将SSL证书分配给IIS站点:

# ensure you have the IIS module imported
Import-Module WebAdministration

cd IIS:\SslBindings
Get-Item cert:\LocalMachine\My\7ABF581E134280162AFFFC81E62011787B3B19B5 | New-Item 0.0.0.0!443
需要注意的事情。。。值“7ABF581E134280162AFFFC81E62011787B3B19B5”是要导入的证书的指纹。因此,需要首先将其导入到证书存储中。
New Item
cmdlet接收IP地址(所有IP为0.0.0.0)和端口

有关更多详细信息,请参阅


我已经在Windows Server 2008 R2和Windows Server 2012预发行版中对此进行了测试。

使用本文中的答案,我创建了一个脚本,为我实现了这一点。它从pfx文件开始,但您可以跳过该步骤

这是:

cd C:\Windows\System32\inetsrv

certutil -f -p "pa$$word" -importpfx "C:\temp\mycert.pfx"

REM The thumbprint is gained by installing the certificate, going to cert manager > personal, clicking on it, then getting the Thumbprint.
REM Be careful copying the thumbprint. It can add hidden characters, esp at the front.
REM appid can be any valid guid
netsh http add sslcert ipport=0.0.0.0:443 certhash=5de934dc39cme0234098234098dd111111111115 appid={75B2A5EC-5FD8-4B89-A29F-E5D038D5E289}

REM bind to all ip's with no domain. There are plenty of examples with domain binding on the web
appcmd set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:']

如果您试图在不使用MMC管理单元GUI的情况下执行IIS管理,则应使用powershell WebAdministration模块


本博客上的其他答案不适用于Windows Server(2012)的更高版本

使用
PowerShell
+
netsh

$certificateName = 'example.com'
$thumbprint = Get-ChildItem -path cert:\LocalMachine\My | where { $_.Subject.StartsWith("CN=$certificateName") } | Select-Object -Expand Thumbprint
$guid = [guid]::NewGuid().ToString("B")
netsh http add sslcert ipport="0.0.0.0:443" certhash=$thumbprint certstorename=MY appid="$guid"
如果需要命名绑定,请将
netsh
调用替换为:

netsh http add sslcert hostnameport="$certificateName:443" certhash=$thumbprint certstorename=MY appid="$guid"

我只是为appid使用随机GUID对我不起作用:SSL证书添加失败,错误:183无法在该文件已存在的情况下创建文件。键入
netsh http show sslcert
将给出计算机上安装的证书的appid和certhash。问候,来自未来的powershellers。请记住在appid={xxxxxxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}中添加单引号。有人能详细说明如何获取特定站点的应用程序id吗?我试着获取StartApps,但其中似乎没有列出任何网站。@TLS-crap。添加了回送计算机链接。我喜欢使用Get-Item cert:\LocalMachine\My*利用AD配置的SSL证书的方式。此命令成功,但在iis窗口中未为我选择SSL证书,这实际上是做什么的?为什么使用
netsh
appcmd
?我试图理解这个过程,但在我看来,他们在做同样的事情(为所有IP创建绑定)。我丢了什么东西吗?