跳到主要内容
IIS

GeoTrust SSL 证书 IIS 安装部署实战:PFX 导入、TLS 1.2 与证书链验证

1. 问题背景与根因:为什么 GeoTrust 证书在 IIS 上容易“装上了但链不全”

GeoTrust 现属 DigiCert 旗下,定位中端 OV 证书,价格通常比 DigiCert 主品牌低约 40%,组织验证审核稳定,适合预算有限但仍需要企业身份验证的站点。IIS 部署与 Nginx/Apache 最大的差异是:IIS 不直接读取 .crt 和 .key,而是使用 PFX(PKCS12)文件,PFX 内应同时包含叶子证书、中间证书和私钥。很多“浏览器能打开、Java 或小程序报错”的根因不是证书无效,而是 PFX 只含叶子证书,服务器没有下发完整证书链。

另一个常见根因是 TLS 协议配置。Windows Server 2012 R2 及更早版本可能默认未启用 TLS 1.2,而现代客户端已逐步停用 TLS 1.0/1.1;需要在 Schannel 注册表中显式启用 TLS 1.2。还要注意公共 TLS 证书最长有效期已限制为 398 天,Let’s Encrypt 证书有效期为 90 天,因此续期和重新绑定必须脚本化,不能依赖手工操作。IIS 绑定还涉及 SNI:同一 IP 和 443 端口部署多个 HTTPS 站点时,必须启用 SNI,否则可能命中错误证书。常见现象包括:`netsh http show sslcert` 显示的 Certificate Hash 与预期不一致、绑定后仍返回旧证书、HTTP 跳转规则写成 301 后出现循环重定向。下面按文件准备、导入绑定、TLS 配置、证书链验证、错误排查和上线检查逐步展开,命令可直接在 Windows Server PowerShell 中执行。

2. 准备 GeoTrust 证书文件:CSR、fullchain 与 PFX 转换

先在服务器或安全环境生成私钥和 CSR。私钥权限应限制,不要通过聊天工具明文传输。示例命令:

openssl req -new -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr -subj '/C=CN/ST=Shanghai/L=Shanghai/O=Example Co., Ltd./CN=example.com'

将 CSR 提交给 GeoTrust 完成 OV 审核后,会得到站点证书和中间证书。不要把中间证书漏掉。构建 fullchain 并检查有效期、主体和签发者:

cat example.com.crt intermediate.crt > fullchain.pem
openssl x509 -in example.com.crt -noout -subject -issuer -dates
openssl verify -CAfile root.pem -untrusted intermediate.crt example.com.crt

转换为 IIS 可导入的 PFX,密码使用强口令并妥善保存:

openssl pkcs12 -export -out example.com.pfx -inkey example.com.key -in fullchain.pem -certfile intermediate.crt -name 'example.com' -passout pass:StrongPass123
openssl pkcs12 -in example.com.pfx -info -noout

文件清单如下:站点证书用于域名身份,中间证书用于补齐链,私钥用于 PFX 解密和握手,PFX 是 IIS 导入入口。若 CA 直接提供 PFX,也要用 `openssl pkcs12 -info` 确认包含私钥和中间证书。注意 GeoTrust 公共证书单次最长不超过 398 天,续期时不要继续使用旧 PFX 文件名覆盖而不更新绑定,建议按 `example.com-2025.pfx` 命名并记录指纹。

3. IIS 导入 PFX 与站点 HTTPS 绑定(GUI + PowerShell)

图形界面路径:IIS 管理器 → 服务器节点 → 服务器证书 → 导入 → 选择 `example.com.pfx` → 输入导出密码 → 证书存储选择“个人/My”。随后选中站点 → 绑定 → 添加 → 类型 https → 端口 443 → 主机名填 `example.com` → 勾选“需要服务器名称指示(SNI)” → 选择刚导入的证书。若多站点共用 443,SNI 必须勾选。PowerShell 可重复执行:

Import-PfxCertificate -FilePath C:certsexample.com.pfx -CertStoreLocation Cert:LocalMachineMy -Password (ConvertTo-SecureString -String 'StrongPass123' -AsPlainText -Force)
Import-Certificate -FilePath C:certsintermediate.crt -CertStoreLocation Cert:LocalMachineCA
$thumb = (Get-ChildItem Cert:LocalMachineMy | Where-Object {$_.Subject -like '*CN=example.com*'}).Thumbprint
New-WebBinding -Name 'example.com' -Protocol https -Port 443 -HostHeader example.com -SslFlags 1
(Get-WebBinding -Name 'example.com' -Protocol https).AddSslCertificate($thumb,'My')

绑定后核对 HTTP.sys 中的 SSL 绑定:

netsh http show sslcert hostnameport=example.com:443

输出中重点看 Certificate Hash 是否等于新证书指纹、Application ID 是否为 IIS 使用的 GUID、CertStoreName 是否为 MY。若显示旧 Hash,说明绑定未更新或存在重复绑定;可先 `netsh http delete sslcert hostnameport=example.com:443` 再重新绑定,但生产环境操作前先导出配置。导入 PFX 时若提示“证书没有私钥”,说明 PFX 不含私钥或导入到了错误存储区,应重新导出并导入到 LocalMachineMy。

4. 配置 TLS 1.2/1.3 与 HTTP 强制跳转

Windows Server 需在 Schannel 中启用 TLS 1.2,禁用 TLS 1.0/1.1。以下 PowerShell 以管理员身份执行,修改后重启服务器或至少重启 IIS:

New-Item -Path 'HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.2Server' -Force
New-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.2Server' -Name 'Enabled' -Value 1 -PropertyType DWord -Force
New-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.2Server' -Name 'DisabledByDefault' -Value 0 -PropertyType DWord -Force
New-Item -Path 'HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.0Server' -Force
New-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.0Server' -Name 'Enabled' -Value 0 -PropertyType DWord -Force
New-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.0Server' -Name 'DisabledByDefault' -Value 1 -PropertyType DWord -Force
iisreset /restart

HTTP 跳转建议使用 IIS URL Rewrite 模块。在站点根目录 web.config 中加入:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name='Redirect to HTTPS' stopProcessing='true'>
          <match url='(.*)' />
          <conditions>
            <add input='{HTTPS}' pattern='off' ignoreCase='true' />
          </conditions>
          <action type='Redirect' url='https://{HTTP_HOST}/{R:1}' redirectType='Permanent' />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

如果站点前面还有负载均衡或 CDN,要确认 `{HTTPS}` 变量是否被代理改写,否则会出现 301 循环。HSTS 可在 HTTPS 响应头添加 `Strict-Transport-Security: max-age=31536000; includeSubDomains`,但首次上线不要立刻加 `preload`。TLS 1.3 在 Windows Server 2022 上支持更好,旧系统不要强行启用。

5. 证书链与中间证书配置示例:用 certutil 与 openssl 验证

IIS 导入 PFX 后,用 certutil 检查个人存储和中间 CA 存储:

certutil -store My example.com
certutil -store CA

个人存储中应看到站点证书和私钥标记,中间 CA 存储中应看到 GeoTrust/DigiCert 中间证书。若中间证书缺失,可执行:

certutil -addstore CA C:certsintermediate.crt

从外部机器验证链是否完整,重点看 depth 层级和返回码:

openssl s_client -connect example.com:443 -servername example.com -showcerts -CAfile /etc/ssl/certs/ca-certificates.crt

正确输出应类似:

depth=2 C = US, O = DigiCert Inc, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, CN = DigiCert TLS RSA SHA256 2020 CA1
verify return:1
depth=0 CN = example.com
verify return:1
Verify return code: 0 (ok)

若出现 `verify error:num=20:unable to get local issuer certificate`,说明服务器没有下发中间证书,常见原因是 PFX 只含叶子证书或 IIS 绑定选错证书。此时不要只在本机浏览器测试,本机信任库可能已缓存中间证书而掩盖问题。正确做法是重新用 fullchain 导出 PFX,导入后重启 IIS,并用另一台机器执行 `openssl s_client` 和 `curl -v` 双重复核。

6. GeoTrust、DigiCert、Let’s Encrypt 与 Sectigo 对比表

项目 GeoTrust OV DigiCert OV Let’s Encrypt DV Sectigo OV
验证类型 组织验证 OV 组织验证 OV 域名验证 DV 组织验证 OV
典型有效期 最长不超过 398 天,通常按 1 年签发 最长不超过 398 天 90 天,需自动续期 最长不超过 398 天
价格定位 中端,约为 DigiCert 主品牌 60% 高端 免费 中低端
信任链 DigiCert Global Root DigiCert Global Root ISRG Root X1 Sectigo/USERTrust
适用场景 预算有限但需 OV 的企业站 大型企业、合规要求高 自动化、个人项目 性价比 OV 站点

选择时不要只看价格。GeoTrust 的优势是 DigiCert 体系信任链、OV 审核稳定,适合 IIS 单站或少量站点;Let’s Encrypt 免费且 90 天自动续期成熟,但只做 DV,不显示组织信息;DigiCert 主品牌价格更高,适合品牌和合规要求强的场景;Sectigo 常作为低成本 OV 备选。无论选哪种,公共 TLS 证书最长 398 天的限制都适用,Let’s Encrypt 更短为 90 天,因此证书续期、PFX 重新导入、IIS 绑定更新和 `iisreset` 应纳入同一套运维脚本。价格会随渠道和年限变化,采购前以 CA 或代理商实时报价为准。

7. 常见错误排查:真实报错与修复命令

报错 1:`curl: (60) SSL certificate problem: unable to get local issuer certificate`。原因通常是服务器未下发中间证书。修复:用 `cat example.com.crt intermediate.crt > fullchain.pem` 重建链,重新导出 PFX 并导入;或在 IIS 服务器执行 `certutil -addstore CA intermediate.crt`,然后 `iisreset /restart`。用 `openssl s_client -showcerts` 确认返回了 depth=1 中间证书。

报错 2:Java 报 `sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target`,小程序报 `request:fail ssl handshake error`。先确认证书链完整和 TLS 1.2 已启用;若 Java 客户端信任库过旧,导入根证书:`keytool -importcert -alias digicertglobalroot -file DigiCertGlobalRootCA.crt -keystore $env:JAVA_HOMElibsecuritycacerts`。小程序还需检查域名备案、HTTPS 端口和 SNI。

报错 3:证书与私钥不匹配,PFX 导出时报 `Mac verify error: invalid password?` 或 `PKCS12_parse: mac verify failure`。分别计算模数:`openssl x509 -in example.com.crt -noout -modulus | openssl md5` 和 `openssl rsa -in example.com.key -noout -modulus | openssl md5`,两个 MD5 必须一致。不一致说明 CSR、私钥、证书不是同一对,需要重新签发或找回正确私钥。

报错 4:IIS 绑定提示 `The certificate cannot be used for SSL because it does not have a private key`。说明导入的证书没有私钥。用 `openssl pkcs12 -in example.com.pfx -nodes` 检查是否出现 `BEGIN PRIVATE KEY`,重新导出含私钥的 PFX,并导入到 `Cert:LocalMachineMy`。若续期后仍返回旧证书,执行 `netsh http show sslcert hostnameport=example.com:443` 核对 Hash,再 `iisreset /restart`。

8. 效果验证与上线检查清单

先在本机执行基础检查:

curl -I https://example.com
curl -v https://example.com
openssl s_client -connect example.com:443 -servername example.com -verify_return_error -brief
netsh http show sslcert hostnameport=example.com:443
Get-ChildItem Cert:LocalMachineMy | Where-Object {$_.Subject -like '*example.com*'} | Select Subject,NotAfter,Thumbprint

`openssl` 输出应包含 `Verification: OK`,`curl` 不应出现证书验证错误。`netsh` 输出中的 Certificate Hash 必须与 IIS 绑定证书指纹一致。再从另一台不在同一信任环境的机器访问,避免本机缓存中间证书导致误判。上线检查清单:HTTPS 443 可访问;HTTP 自动 301 到 HTTPS;证书链完整;证书有效期未超过 398 天且剩余时间大于 30 天;TLS 1.0/1.1 已禁用;TLS 1.2 已启用;SNI 已勾选;绑定指纹与 PFX 一致;`iisreset` 后配置仍生效;外部 SSL Labs 或 openssl 检测无链错误。若使用 CDN,还要在 CDN 侧上传完整链证书并回源验证,否则边缘节点正常、回源仍可能报错。

常见问题

是。IIS 通过 PFX(PKCS12)导入证书、中间证书和私钥,不能直接读取 .crt 与 .key。用 openssl pkcs12 -export 将 fullchain 和私钥导出为 PFX,再导入 LocalMachineMy。PFX 必须含私钥,否则绑定会提示证书没有私钥。

用另一台机器执行 openssl s_client -connect 域名:443 -servername 域名 -showcerts,若只看到 depth=0 叶子证书或报 unable to get local issuer certificate,说明中间证书未下发。重新用 fullchain 导出 PFX,或在 IIS 服务器把中间证书导入中间 CA 存储后重启 IIS。

先执行 netsh http show sslcert hostnameport=域名:443 核对 Certificate Hash 是否为新指纹。若仍是旧值,在 IIS 绑定中重新选择新证书;若已更新,执行 iisreset /restart 并清理 CDN 或反向代理缓存。多站点共用 443 时还要确认 SNI 绑定正确。

公共 TLS 证书单次最长有效期为 398 天,GeoTrust 通常按 1 年签发但不会超过该上限。Let’s Encrypt 为 90 天。建议在到期前 30 天完成续期、PFX 重新导入、IIS 绑定更新和重启验证,避免因 398 天限制导致过期。

在站点绑定中添加 https/443,填写不同主机名,并勾选需要服务器名称指示 SNI。PowerShell 可用 New-WebBinding 加 -SslFlags 1。绑定后用 netsh http show sslcert hostnameport=域名:443 核对每个主机名对应的证书指纹,避免命中错误证书。

内容审核

长期从事 SSL/TLS 证书部署与 HTTPS 运维,负责本站证书选型、安装配置与故障排查内容的编写与审核。