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

时间:2009-02-26 17:37:54

标签: 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

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

7 个答案:

答案 0 :(得分:51)

答案是使用NETSH。 例如

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

答案 1 :(得分:17)

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

http://www.awesomeideas.net/post/How-to-configure-SSL-on-IIS7-under-Windows-2008-Server-Core.aspx

编辑:如果原始网址已关闭,则该网址仍然可用through the Wayback Machine

答案 2 :(得分:9)

使用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)和端口。

有关详细信息,请参阅http://learn.iis.net/page.aspx/491/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in/

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

答案 3 :(得分:4)

@David和@orip说对了。

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

我去查了一下,所以我想我会在这里记录以节省其他人的时间。本文重点介绍SQL Server,但信息仍然相关:

http://msdn.microsoft.com/en-us/library/ms186362.aspx

答案 4 :(得分:1)

使用这篇文章的答案,我创建了一个单独的脚本,为我做了诀窍。它从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:']

答案 5 :(得分:0)

如果尝试不使用MMC管理单元GUI来执行IIS管理,则应使用Powershell WebAdministration模块。

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

答案 6 :(得分:0)

使用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"