Powershell Octopus Deploy-用于在IIS上设置SSL绑定的Deploy.ps1脚本
使用八达通部署脚本创建网站找到 我正在尝试建立一个使用SSL的网站。我已经更改了Powershell Octopus Deploy-用于在IIS上设置SSL绑定的Deploy.ps1脚本,powershell,iis-7,ssl-certificate,octopus-deploy,Powershell,Iis 7,Ssl Certificate,Octopus Deploy,使用八达通部署脚本创建网站找到 我正在尝试建立一个使用SSL的网站。我已经更改了http->https,变量设置为$MyWebAppIisBindings=“*:433:” 此脚本执行创建新站点和部署我的应用程序的所有操作,但设置证书除外 我有一个名为'webserver'的证书,可以从IIS 7管理器中“编辑站点绑定”对话框的组合框中选择。手动选择此选项可使SSL按预期工作 为了将我的证书与IIS上的绑定相关联,我需要向部署脚本添加什么Powershellcmdlet (我是一个彻头彻尾的Po
http->https
,变量设置为$MyWebAppIisBindings=“*:433:”
此脚本执行创建新站点和部署我的应用程序的所有操作,但设置证书除外
我有一个名为'webserver'
的证书,可以从IIS 7管理器中“编辑站点绑定”对话框的组合框中选择。手动选择此选项可使SSL按预期工作
为了将我的证书与IIS上的绑定相关联,我需要向部署脚本添加什么Powershellcmdlet
(我是一个彻头彻尾的Powershell noob,请不要在你的回答中假设我知道任何关于它的事情)
编辑:我进步了一点,但还是迷路了
# think I need to do something like this to get the certificate
# Get-Item cert:\LocalMachine\My\$siteCertThumb
# but I have no idea how to assign it to the 443 binding
除了您已经做的两项更改,
http->https
和80->443
将以下内容添加到部署脚本的末尾。其中$siteCertThumb是存储在LocalMachine\My store中的证书的指纹
Write-Host "Add certificate to binding..."
Get-Item CERT:\LocalMachine\MY\$siteCertThumb | New-Item IIS://SslBindings/$siteBindings
为了扩展Jared的答案,下面是最近一个使用HTTP和HTTPS的项目的完整脚本:
#
# Settings
#---------------
$appPoolName = ("Kraken-Pool-" + $OctopusEnvironmentName)
$siteName = ("Kraken - " + $OctopusEnvironmentName)
$siteBindings = ":80:octopushq.com"
$siteBindingsSecure = ":443:octopushq.com"
$siteCertificate = "CERT:\LocalMachine\WebHosting\A347FC4B77A2C176E451D8CE4973C7D0FB3E19AA"
$appPoolFrameworkVersion = "v4.0"
$webRoot = (resolve-path .)
# Installation
#---------------
Import-Module WebAdministration
cd IIS:\
$appPoolPath = ("IIS:\AppPools\" + $appPoolName)
$pool = Get-Item $appPoolPath -ErrorAction SilentlyContinue
if (!$pool) {
Write-Host "App pool does not exist, creating..."
new-item $appPoolPath
$pool = Get-Item $appPoolPath
} else {
Write-Host "App pool exists."
}
Write-Host "Set .NET framework version:" $appPoolFrameworkVersion
Set-ItemProperty $appPoolPath managedRuntimeVersion $appPoolFrameworkVersion
Write-Host "Set identity..."
Set-ItemProperty $appPoolPath -name processModel -value @{identitytype="NetworkService"}
Write-Host "Checking site..."
$sitePath = ("IIS:\Sites\" + $siteName)
$site = Get-Item $sitePath -ErrorAction SilentlyContinue
if (!$site) {
Write-Host "Site does not exist, creating..."
$id = (dir iis:\sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
new-item $sitePath -bindings @{protocol="http";bindingInformation=$siteBindings} -id $id -physicalPath $webRoot
} else {
Write-Host "Site exists. Complete"
}
Write-Host "Set app pool..."
Set-ItemProperty $sitePath -name applicationPool -value $appPoolName
Write-Host "Set bindings..."
Set-ItemProperty $sitePath -name bindings -value @{protocol="http";bindingInformation=$siteBindings}
New-ItemProperty $sitePath -name bindings -value @{protocol="https";bindingInformation=$siteBindingsSecure}
Get-Item $siteCertificate | Set-Item IIS://SslBindings/0.0.0.0!443
Write-Host "Set path..."
Set-ItemProperty $sitePath -name physicalPath -value "$webRoot"
Write-Host "IIS configuration complete!"
在下面的15页,我们使用八达通,并构建了一个开源的八达通助手 helper PowerShell中的一个功能包括安装到IIS和添加SSL证书 项目本身可在此处找到: 关于如何使用帮助程序,请首先参考createWebSite.ps1。-如果您使用的是IIS6或II7,则此操作有效。 然后创建应用程序池、网站并添加ssl证书 这里有一个小例子
$deployTools = "D:\DeployTools\"
. $deployTools\createWebSite.ps1
CreateAppPool "MyAppPool"
CreateWebsite "MyWebsite" "D:\WebsiteDir" "MyAppPool" "MyAppName" "myWebsite.com" "D:\Logs\MyWebsite"
AddSslCertificate "MyWebsite" "CertificateName" "myWebsite.com"
您还可以使用Enscence工具部署应用程序并更新任何配置数据。-更多信息可以在GitHub wiki上找到