首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为网站绑定选择新安装的SSL证书?

问如何为网站绑定选择新安装的SSL证书?
EN

Stack Overflow用户
提问于 2018-08-19 20:49:13
回答 2查看 3K关注 0票数 1

我使用cert命令来添加ssl证书,但是在添加证书之后,如何使用power为所有托管的网站选择新的证书?

我尝试在powershell下面选择新安装的证书,但我得到了错误SSL证书添加失败,错误: 183不能创建一个文件时,该文件已经存在。有时,SSL证书添加失败,错误: 1312指定的登录会话不存在。它可能已经被终止了

代码语言:javascript
复制
$hostname="*.domain.net"
$cert = (Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like "*$hostname*" } | Select-Object -First 1).Thumbprint
$guid = [guid]::NewGuid().ToString("B")
netsh http add sslcert ipport="${IPAddressV2}:443" certhash=$cert certstorename=MY appid="$guid"
netsh http add sslcert ipport="${IPAddressV3}:443" certhash=$cert certstorename=MY appid="$guid"
netsh http add sslcert ipport="127.0.0.1:443" certhash=$cert certstorename=MY appid="$guid"
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-20 12:41:19

下面是工作脚本,它自动为端口号为443的所有绑定选择新安装的证书。

代码语言:javascript
复制
Import-Module Webadministration
    IIS:
    $IPAddress = "C:\Ipaddress.txt"
    $Bindings = Get-WebBinding | Where-Object {$_.protocol -eq "https"} | Select-Object -ExpandProperty bindingInformation 
    $IPs = $Bindings | ForEach-Object { @($_ -split ':')[0]}
    $IPs = @($IPs |Sort-Object -Unique) > $IPAddress

    Import-Module Webadministration
    $Friendlyname="*.abcd.com"
    Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like "*$Friendlyname*" }
    $hostname = Get-Content C:\Ipaddress.txt 
    foreach ($name in $hostname) { 
    $cert = (Get-ChildItem cert:\LocalMachine\My | where-object { $_.Subject -like "*$Friendlyname*" } | Select-Object -First 1).Thumbprint
    Remove-Item -path "IIS:\SslBindings\${name}!443"
    TIMEOUT /T 5 /NOBREAK
    New-Item -path "IIS:\SslBindings\$name!443" -Thumbprint $cert}
票数 1
EN

Stack Overflow用户

发布于 2018-08-20 03:26:21

您正在尝试将SSL证书绑定到外卡主机名。SSL是每个网站一个,虽然SSL证书可以是通配符,但是站点应该是唯一的名称。

如本文进一步讨论的那样..。

https://learn.microsoft.com/en-us/iis/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in

。。在这篇文章中,/answer。

Powershell - Set SSL Certificate on https Binding

根据OP请求更新

假设这是IIS。最好也导入WebAdministration模块,将所有IIS和IIS都放在手边。

代码语言:javascript
复制
# Set SSL bindings for the default site, as an example
New-WebBinding -Name "Default Web Site" -Protocol "https" -IPAddress "10.10.0.3" -Port 443 -HostHeader "intranet.corp.contoso.com"

$SSLCert = Get-ChildItem –Path "cert:\LocalMachine\My" | 
Where-Object {$_.subject -like 'cn=intranet*'}

New-Item "IIS:SslBindings\10.10.0.3!443" -value $SSLCert

这里是主要的IIS文章,可以利用IIS人员。在这篇文章中有很多例子,我已经摘录了一些相关的案例,这些案例应该能帮助你找到你需要去的地方。

IIS用户指南-比较有代表性的IIS任务https://blogs.iis.net/jeonghwan/iis-powershell-user-guide-comparing-representative-iis-ui-tasks

代码语言:javascript
复制
# Related UI Task:"Add Web Site..." wizard

# 18.[Sites] Set bindings 
Case1: Create SSL Binding (127.0.0.1!443)
$certObect=get-item cert:LocalMachineMyE48803C3A6DDC8F2BFE3D8B7B7D56BBA70270F92new-item IIS:SslBindings127.0.0.1!443 -value $certObect

# Case2: Set 'Bindings' property with multiple binding information including the SSL binding which was created above.
$newBinding=(@{protocol="http";bindingInformation="127.0.0.1:80:normalSite"},@{protocol="https";bindingInformation="127.0.0.1:443:securedSite"})
Set-itemproperty "IIS:SitesDefault Web Site" -name bindings -value $newBinding


# Or, you can use other task-based  cmdlet(s) instead:
New-WebBinding -Site "Default Web Site" -Port 443 -IPAddress 127.0.0.1 -HostHeader securedSite


# NOTE: you can also use set-webconfiguration, set-webconfiguration or add-webconfigurationProperty.
Set-Webconfiguration '/system.applicationHost/sites/site[@name="Default Web Site"]/bindings' -value $newBinding  -PSPath iis:
Set-WebconfigurationProperty '/system.applicationHost/sites/site[@name="Default Web Site"]' -name bindings.collection -value $newBinding -at 0  -PSPath iis:
Add-WebconfigurationProperty '/system.applicationHost/sites/site[@name="Default Web Site"]' -name bindings.collection -value @{protocol="https";bindingInformation="127.0.0.1:443:securedSite"} -at 0  -PSPath iis:
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51921743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档