【问题标题】:Octopus Deploy - Deploy.ps1 script for setting up SSL bindings on IISOctopus Deploy - 用于在 IIS 上设置 SSL 绑定的 Deploy.ps1 脚本
【发布时间】:2012-12-28 02:36:57
【问题描述】:

使用章鱼部署脚本创建网站发现here

我正在尝试建立一个使用 SSL 的网站。我更改了http -> https,变量设置为此$MyWebAppIisBindings = "*:433:"

除了设置证书之外,此脚本会执行所有操作来创建新站点并部署我的应用程序。

我有一个名为'webserver' 的证书,可以从 IIS 7 管理器的编辑站点绑定对话框的组合框中选择。手动选择此项可使 SSL 按预期工作。

我需要向部署脚本添加什么 Powershell cmdlet 才能将我的证书与我在 IIS 上的绑定相关联?

(我是一个完整的 Powershell 菜鸟,请不要在你的回答中假设我对此一无所知)

编辑:我进步了一点,但我仍然迷路

# 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

【问题讨论】:

    标签: powershell iis-7 ssl-certificate octopus-deploy


    【解决方案1】:

    为了扩展 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!"
    

    【讨论】:

      【解决方案2】:

      在 15below 我们使用 octopus 并构建了一个开源 octopus helper。

      helper powershells 中的一个功能包括安装到 IIS 和添加 SSL 证书。

      项目本身可以在这里找到:https://github.com/15below/Ensconce

      关于如何使用helper,首先参考createWebSite.ps1。 - 如果您使用的是 IIS6 或 7,这可以解决。 然后创建应用程序池、网站并添加 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"
      

      您还可以使用 ensconce 工具来部署您的应用程序并更新任何配置数据。 - 更多信息可以在 GitHub wiki 上找到。

      【讨论】:

        【解决方案3】:

        除了您已经进行的两个更改,http -> https80 -> 443

        将以下内容添加到部署脚本的末尾。其中 $siteCertThumb 是存储在 LocalMachine\My 商店中的证书的指纹。

        Write-Host "Add certificate to binding..."
        Get-Item CERT:\LocalMachine\MY\$siteCertThumb | New-Item IIS://SslBindings/$siteBindings
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-01-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多