GlobalSign SSL 证书 IIS 安装部署教程:PFX 导入、TLS 1.2 与证书链排错
1. 问题背景与根因:IIS 部署 GlobalSign 证书为什么容易失败
GlobalSign 是欧洲老牌 CA,除 SSL 外还提供文档签名、S/MIME 等合规产品,欧洲和日本市场占有率高。把 GlobalSign 签发的 SSL 证书部署到 IIS,表面只是导入 PFX 和绑定 443,实际涉及 PKCS#12 私钥、中间证书链、SNI 主机名绑定和 Windows Schannel 协议栈四个环节。公共可信 TLS 证书单张最长有效期为 398 天,Let’s Encrypt 为 90 天,续期频率不同,但 IIS 部署链路一致。
最常见的根因不是证书本身,而是:只导入了叶子证书 .crt,没有导入 GlobalSign 中间证书;PFX 导出时未带私钥;443 端口多站点未启用 SNI,导致命中默认站点证书;Windows Server 未启用 TLS 1.2;续期后只替换文件,没有更新 IIS 绑定或重启应用池。先用 certutil -store My 查看本机证书存储,再用 netsh http show sslcert 核对 443 绑定,能快速定位问题在证书、绑定还是协议层。
部署前要明确:IIS 使用 PFX(PKCS#12)格式,PFX 内应同时包含站点证书、GlobalSign 中间证书和私钥。CSR 只在申请阶段使用,部署阶段不需要再提交 CSR。若 CA 只给 .crt 和 .key,需要自行合成 fullchain 并导出 PFX。
2. 准备证书文件:CSR、fullchain 与私钥一致性校验
向 GlobalSign 下单时提交 CSR,私钥必须留在本机。生成 2048 位 RSA 私钥和 CSR 的命令如下,CN 写主域名,SAN 由 CA 订单填写:
openssl req -new -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr -subj '/CN=example.com'
收到证书后,把站点证书和中间证书按“叶子证书 → 中间证书”的顺序拼接为 fullchain.pem。GlobalSign 常见中间证书为 GlobalSign RSA OV SSL CA 2018 等,必须以签发邮件或 CA 仓库下载的最新链为准。导出 PFX:
openssl pkcs12 -export -out example.com.pfx -inkey example.com.key -in fullchain.pem -certfile chain.pem -name 'GlobalSign example.com' -passout pass:StrongPass123
如果 fullchain.pem 已包含中间证书,-certfile chain.pem 可省略;但不要只放叶子证书。导出后检查 PFX 是否含私钥和链:
openssl pkcs12 -in example.com.pfx -info -noout
openssl x509 -in fullchain.pem -noout -subject -issuer -dates -modulus | openssl md5
openssl rsa -in example.com.key -noout -modulus | openssl md5
两条 modulus 的 MD5 必须一致,否则证书与私钥不匹配。再用根证书验证链:openssl verify -CAfile GlobalSignRootR3.pem -untrusted chain.pem example.com.crt。GlobalSign 公共 TLS 证书单张最长 398 天,建议到期前 30 天续期;Let’s Encrypt 为 90 天,需更频繁自动化续期。
3. 完整实操:在 IIS 中导入 PFX 并绑定 HTTPS
以管理员身份打开 IIS 管理器,点服务器节点 → 服务器证书 → 导入,选择 example.com.pfx,输入导出密码,证书存储选“个人/My”。也可用 PowerShell 导入到 LocalMachineMy:
Import-PfxCertificate -FilePath C:\certs\example.com.pfx -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String 'StrongPass123' -AsPlainText -Force)
然后给站点添加 HTTPS 绑定:站点 → 绑定 → 添加 → 类型 https → 端口 443 → 主机名 example.com → 选择刚导入的证书。若同一台服务器有多个 443 站点,必须勾选“需要服务器名称指示”(SNI),否则先匹配到的默认站点会返回错误证书。PowerShell 可创建绑定:
New-WebBinding -Name 'example.com' -Protocol https -Port 443 -HostHeader 'example.com' -SslFlags 1
$thumb = (Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -like '*CN=example.com*'} | Select-Object -First 1).Thumbprint
netsh http add sslcert hostnameport=example.com:443 certhash=$thumb appid={4dc3e181-e14b-4a21-b022-59fc669b0914} certstorename=MY
如果绑定已存在,netsh http add sslcert 会报“A certificate already exists for the specified IP/port”,应先用 netsh http show sslcert hostnameport=example.com:443 查看,再 netsh http delete sslcert hostnameport=example.com:443 后重加。导入后确认私钥可用:IIS 管理器证书列表应显示证书有私钥;若显示“找不到与此证书匹配的私钥”,回到第 2 节重新导出 PFX。
4. 配置示例:HTTP 跳转 HTTPS 与启用 TLS 1.2
先安装 IIS URL Rewrite 模块,否则 web.config 的 rewrite 节会触发 500.19。站点根目录 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>
Windows Server 还需在 Schannel 中启用 TLS 1.2,并建议禁用 TLS 1.0/1.1。以管理员 PowerShell 执行:
New-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Force
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Name 'Enabled' -Value 1 -PropertyType DWord -Force
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Name 'DisabledByDefault' -Value 0 -PropertyType DWord -Force
改注册表后重启服务器或至少重启 IIS:iisreset /noforce。如果站点使用应用池身份读取证书,还需确保应用池账号对 PFX 导入后的私钥有读取权限;生产环境不建议把 PFX 密码写进脚本,可用 Get-Credential 或密钥管理服务。
5. 对比表格:IIS 部署方式与证书有效期
不同部署方式适合不同场景,核心差异在是否可脚本化、是否精确控制 SNI 和端口绑定:
| 方式 | 适用场景 | 关键命令/入口 | 注意事项 |
|---|---|---|---|
| IIS 管理器导入 PFX | 单站点、图形化运维 | 服务器证书 → 导入 | 必须选个人存储,确认证书有私钥 |
| PowerShell Import-PfxCertificate | 批量、自动化 | Import-PfxCertificate -FilePath ... -CertStoreLocation Cert:\LocalMachine\My |
需管理员权限,密码用 SecureString |
| certutil 导入 | 无 GUI、脚本 | certutil -importpfx -p StrongPass123 C:\certs\example.com.pfx |
注意存储区和私钥权限 |
| netsh http add sslcert | 精确控制 SNI/443 绑定 | netsh http add sslcert hostnameport=example.com:443 ... |
已有绑定先 delete 或 update |
有效期方面,GlobalSign 公共可信 TLS 证书按 CA/B Forum 规则单张最长 398 天;Let’s Encrypt 为 90 天。二者都要求提前规划续期,但 IIS 部署时都要重新导入新 PFX、更新绑定并重启应用池,不能只覆盖磁盘上的证书文件。
6. 常见错误排查:真实报错与修复命令
报错 1:The certificate cannot be used for SSL because it does not have a private key 或 IIS 提示“找不到与此证书匹配的私钥”。说明导入的是叶子 .crt 或 PFX 导出时漏了 -inkey。用 openssl pkcs12 -in example.com.pfx -info -noout 检查,重新导出带私钥的 PFX,并导入 LocalMachineMy。
报错 2:curl 报 SSL certificate problem: unable to get local issuer certificate,Java 报 PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target。这是证书链不完整。用 openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 查看返回链,确保 IIS 绑定的是含 GlobalSign 中间证书的 PFX,fullchain 顺序为叶子 → 中间。
报错 3:浏览器报 NET::ERR_CERT_COMMON_NAME_INVALID 或 ERR_CERT_AUTHORITY_INVALID。前者多为 SNI/主机名绑定错误,检查绑定主机名是否为 example.com;后者多为链不完整或客户端不信任根证书。
报错 4:HTTP Error 500.19 - Internal Server Error,配置错误指向 rewrite 节。安装 IIS URL Rewrite 模块后重启 IIS。
报错 5:A certificate already exists for the specified IP/port。执行 netsh http show sslcert hostnameport=example.com:443 核对指纹,再 netsh http delete sslcert hostnameport=example.com:443 后重新添加。
报错 6:schannel: SSL/TLS connection failed 或“客户端和服务器无法通信,因为它们不具备通用算法”。检查 TLS 1.2 是否启用,按第 4 节注册表配置并重启。证书与私钥不匹配时,用第 2 节 modulus MD5 对比,不一致就重新导出 PFX。
7. 效果验证:本机、命令行与外部机器三重检查
先在服务器本机验证端口和绑定:
Test-NetConnection example.com -Port 443
(Invoke-WebRequest https://example.com -UseBasicParsing).StatusCode
netsh http show sslcert hostnameport=example.com:443
再用 curl 和 openssl 检查证书链、主机名和有效期:
curl -I https://example.com
curl -v https://example.com 2>&1 | grep -E 'SSL certificate|subject|issuer|expire'
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
Java 客户端可执行 keytool -printcert -sslserver example.com:443,小程序、Android、Java 服务端建议从另一台机器访问,避免本机信任库掩盖中间证书缺失。最后用浏览器确认锁图标、证书颁发者为 GlobalSign、有效期不超过 398 天,并检查 HTTP 是否 301 跳转到 HTTPS。生产环境可再用 SSL Labs 或 certutil -verify -urlfetch C:\certs\example.com.cer 做链验证。
常见问题
公共可信 TLS 证书单张最长 398 天,GlobalSign 按 CA/B Forum 规则签发;建议到期前 30 天续期。Let’s Encrypt 为 90 天,续期更频繁,但 IIS 部署流程相同。
确认 PFX 含私钥,用 openssl pkcs12 -info -noout 检查;重新导出时带 -inkey,导入 LocalMachineMy,不要只导入 .crt 叶子证书。
多为证书链不完整。用 openssl s_client -showcerts 检查,确保 IIS 绑定含 GlobalSign 中间证书的 PFX,fullchain 顺序为叶子→中间,而不是只放站点证书。
启用 SNI,每个站点使用不同主机名绑定,绑定信息写成 *:443:example.com;不支持 SNI 的旧客户端需独立 IP 或统一证书。
重新导入新 PFX,更新 IIS 站点绑定,重启站点和应用池,必要时执行 iisreset;再用 netsh http show sslcert 核对指纹和有效期。
必须。Windows Server 可能默认未启用,按第 4 节在 Schannel 注册表启用 TLS 1.2 并禁用 TLS 1.0/1.1,重启后验证。