LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

windows服務器申請SSL證書及自動續期

freeflydom
2025年6月10日 15:14 本文熱度 414

一、證書申請

  • 工具: Certbot
  • 端口需求: 80 
certbot certonly -d example.com --webroot

        交互窗口輸入IIS站點根目錄,以使certbot創建驗證文件(通過http協議地址能夠被訪問到),由于生成驗證文件不具備后綴名,在默認IIS安全設置中是不允許此類鏈接訪問的,因此還需要在網站MIME類型中加個通配符類型『.』,配置其對應的類型為『application/octet-stream』。
        驗證通過后會將證書發布至C:\Certbot文件夾下,archive和live目錄下均會生成域名對應的文件夾,live為有效的archive目錄下快捷方式。
        跳轉到live\example.com目錄下,會有cert.pem, chain.pem, fullchain.pem, privkey.pem幾個生成文件,其中fullchain和privkey是下一步需要的文件。

注: CertBot最新版本只支持Win7或以上系統,對應的Windows Server版本至少需要在Server 2012或以上,若是更早的WinServer操作系統,需要下載低版本的CertBot,主要原因是其依賴的python環境不支持低版本操作系統。

二、證書類型轉換

  • 工具: openssl   
$env:MYPASS = "123"
openssl pkcs12 -export -out example.com.pfx -passout env:MYPASS -in fullchain.pem -inkey privkey.pem

三、證書導入與綁定

certutil -p 123 -importPFX example.com.pfx
$oSsl = $( ls Cert:\LocalMachine\My | ?{ $_.Subject -like "*example.com" } )
Import-Module WebAdministration
New-WebBinding -Name "Default Web Site" -IPAddress "*" -Port 443 -Protocol https
$oBind = Get-WebBinding -Name "Default Web Site" -Port 443 -Protocol https
$oBind.AddSslCertificate($oSsl.Thumbprint, "my")

四、建立自動更新任務

  • 計劃任務建立

         每隔一個月執行自動檢測更新腳本

$oDT = Get-Date -Format "yyyyMMdd"
$nMo = [int]$oDT.substring(4,2) % 2
$strMonths = ""
if ($nMon -eq 1) {
	$strMonths = "1,3,5,7,9,11"
} else {
	$strMonths = "2,4,6,8,10,12"
}
$oDT -Match "(..)(..)(..)"
$strDT = "$($Matches[1])/$($Matches[2])/$($Matches[3])"
schtasks /create /tn UpdateSSL /sc MONTHLY /mo $strMonths /sd "$strDT" /st 00:30:00 /tr "powershell -Command \`"Set-ExecutePolicy -Scope Process Bypass; Start powershell $PWD\UpdateSSL.ps1;\`""
  •  詳細執行內容

        UpdateSSL.ps1

function pause() {
    Write-Host "Press any key to contiune..."
    [Console]::ReadKey() | Out-Null
}
function main() {
    pushd C:\Certbot\live\example.com\
    # Pull update state
    $strRet = $(certbot renew --cert-name example.com)
    $bUpdate = $($strRet | findstr /c:"No renewals")
    if ("$bUpdate" -ne "") {
        Write-Host "No new update, skip..."
    } else {
        Write-Host "Renewals founded, now export pfx file."
        # Backup old cert file
        Write-Host "Step 1: Backup the old pfx file."
        $strDT = $(Get-Date -Format "yyyyMMdd").ToString()
        mv example.com.pfx "backup_${strDT}_example.com.pfx"
        # Export cert as pkcs12 file
        Write-Host "Step 2: Export the new cert to pfx file."
        $env:cert_pass = "123"
        openssl pkcs12 -export -out example.com.pfx -passout env:cert_pass -in fullchain.pem -inkey privkey.pem
        # Delete old pfx in local machine
        Write-Host "Step 3: Delete the certification from cert store."
        ls Cert:\LocalMachine\My | ?{ $_.Subject -like "*example.com"} | rm
        # Import pfx to cert store
        Write-Host "Step 4: Import the new certification to cert store."
        certutil -f -p 123 -importPFX $PWD\example.com.pfx
        # ReBind certification of web site
        Write-Host "Step 5: Rebind the certification to default web site as https protocol."
        $oCert = $( ls Cert:\LocalMachine\My | ?{ $_.Subject -like "*example.com"} )
        $oCert
        $oBind = Get-WebBinding -Name "Default Web Site" -Protocol "https"
        $oBind
        Write-Host " Step 5.1: Remove certification from Default Web Site."
        $oBind.RemoveSslCertificate()
        #pause
        Write-Host " Step 5.2: Add new certification from Default Web Site."
        $oBind.AddSslCertificate($oCert.Thumbprint, "My")
        #pause
        # Restart web site
        Write-Host "Step 6: Restart the Default Web Site."
        $oWebSite = Get-WebSite -Name "Default Web Site"
        $oWebSite.Stop()
        $oWebSite.Start()
    }
    popd
}
main
pause

轉自https://blog.csdn.net/WGLNNGT/article/details/137587148


該文章在 2025/6/10 15:14:13 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
欧美v日韩v亚洲v最新在线 | 日本精品二三区视频在线观看 | 在线免费播放AV片 | 亚洲欧美在线播放 | 亚洲日本视频在线观看 | 亚洲一区欧美日韩 |