IIS服务器SSL证书安装全攻略(Windows 2025)
版本适配:本教程适用于IIS 10/11 (Windows Server 2025/2022)
一、准备工作
- 已获取PFX格式SSL证书文件(含私钥)(从控制台下载)
- 确保服务器已安装URL Rewrite模块
- 开放防火墙443端口:
New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
二、证书安装流程
IIS管理器配置步骤
步骤1:导入PFX证书
# PowerShell管理员模式执行 Import-PfxCertificate -FilePath C:\certs\yourdomain.pfx -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String "your_password" -AsPlainText -Force)
步骤2:配置网站绑定
- 打开IIS管理器 → 选择网站 → 点击【绑定】
- 添加类型为https的绑定,选择导入的证书
- 设置主机名为你的域名




注意:绑定后需重启网站应用更改
三、高级配置
HTTP强制跳转HTTPS
<configuration> <system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>