2026年9月6日 星期日

網路相關 Cloudflare設定SSL

1.登入Cloudflare > 上方選擇要使用的網域 > 左邊選單 SSL/TLS > 原始伺服器
2.金鑰格式PEM,然後將原點憑證存成
C:\Cert\my.cer
3.將私密金鑰存成
C:\Cert\my.key
4-1.安裝OpenSSL,以下是Server 2025直接用cmd or powershell
winget install FireDaemon.OpenSSL
4-2也可以使用下載的方式點我下載
5.將憑證資料合併成pfx,cmd or powershell
4-1 
openssl pkcs12 -export -out C:\Cert\my.pfx -inkey C:\Cert\my.key -in C:\Cert\my.cer
4-2 
openssl.exe pkcs12 -export -out C:\Cert\my.pfx -inkey C:\Cert\my.key -in C:\Cert\my.cer

輸入後會需要您設定一組密碼
6.將憑證加入IIS中,cmd or powershell
$flags = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet -bor `
         [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet -bor `
         [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Cert\my.pfx", "你剛剛設定的密碼", $flags)
$cert.FriendlyName = "www.abc.com"

$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("WebHosting", "LocalMachine")
$store.Open("ReadWrite")
$store.Add($cert)
$store.Close()
7.開啟IIS上將憑證設定上去