代码之家  ›  专栏  ›  技术社区  ›  David Christiansen

如何从命令提示将SSL证书分配给IIS7站点

  •  51
  • David Christiansen  · 技术社区  · 16 年前

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

    我熟悉设置https绑定的命令

    appcmd set site /site.name:"A Site" /+bindings.[protocol='https',bindingInformation='*:443:www.mysite.com']
    

    以及如何获得当前映射

    %windir%\system32\inetsrv\Appcmd
    

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

    5 回复  |  直到 16 年前
        1
  •  51
  •   David Christiansen    8 年前

    答案是使用netsh。 例如

    netsh http add sslcert ipport=0.0.0.0:443 certhash='baf9926b466e8565217b5e6287c97973dcd54874' appid='{ab3c58f7-8316-42e3-bc6e-771d4ce4b201}'
    
        2
  •  17
  •   orip    10 年前

    这对我有很大帮助:一个简单的指南,由SukeshAshokKumar编写,用于从命令行为IIS设置SSL。包括导入/生成证书 certutil / makecert .

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

    编辑:如果原始URL关闭,它仍然可用 through the Wayback Machine .

        3
  •  9
  •   David Mohundro alexsmn    12 年前

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

    注意事项…值“7abf581e134280162affc81e622011787b3b19b5”是要导入的证书的指纹。所以需要先将其导入证书存储。这个 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预发行版中测试过这个功能。

        4
  •  4
  •   fordareh    13 年前

    @大卫和@orip是对的。

    但是,我确实想提到 IP端口 示例中指定的参数(0.0.0.0:443)是msdn所称的“未指定的地址(ipv4:0.0.0.0或ipv6::)”。

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

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

        5
  •  0
  •   JsAndDotNet    7 年前

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