Install a certificate in IIS

In IIS a certificate always hangs on a binding: site, port, host name. The certificate itself lives in the Windows certificate store. Keep the two apart and most problems are already solved.

Three ways to a certificate

Complete the request

Load the CA’s reply (.cer or .crt) under Server Certificates → “Complete Certificate Request”. Important: on the same server where the request was created. Only there is the private key.

If the certificate disappears from the list after completing, the link to the key is missing. This often helps:

certutil -repairstore my "<serial number of the certificate>"

Intermediate certificates

IIS serves the chain that Windows can build from the certificate store. If an intermediate is missing there, it is missing for the visitor too. Fix: import the CA’s intermediate with certlm.msc under Intermediate Certification Authorities and restart the service (iisreset). The SSL check shows whether the chain is right.

The HTTPS binding

  1. In IIS Manager select the site → Bindings → Add.
  2. Type https, port 443, enter the host name.
  3. Tick “Require Server Name Indication” (SNI) if several HTTPS sites run on the same IP. Otherwise one binding wins and other sites show the wrong certificate (ERR_CERT_COMMON_NAME_INVALID).
  4. Select the SSL certificate from the list.

With PowerShell

$pw   = Read-Host -AsSecureString "PFX password"
$cert = Import-PfxCertificate -FilePath C:\certs\server.pfx -CertStoreLocation Cert:\LocalMachine\My -Password $pw

Import-Module WebAdministration
New-WebBinding -Name "Default Web Site" -Protocol https -Port 443 -HostHeader www.example.com -SslFlags 1
(Get-WebBinding -Name "Default Web Site" -Protocol https -HostHeader www.example.com).AddSslCertificate($cert.Thumbprint, "My")

netsh http show sslcert    # shows all assignments

-SslFlags 1 enables SNI. If the certificate comes as PEM from a Linux system, convert it to PFX first, e.g. with the certificate converter or as in the article convert PFX and PEM.

Protocols and ciphers

IIS uses Windows’ TLS settings (Schannel). Windows Server 2022 and later support TLS 1.3. Switch off TLS 1.0 and 1.1 via the registry or conveniently with the IIS Crypto tool; its “Best Practices” template is enough. A reboot is required afterwards.

Typical problems

FAQ

How do I export an IIS certificate for another server?

In IIS Manager under Server Certificates → Export, or in certlm.msc with “export the private key” and “include all certificates in the certification path”.

Do I need a separate IP for each site?

No. With SNI any number of HTTPS sites can share one IP. All current browsers support SNI.

Where do I set HSTS in IIS?

From IIS 10 (Windows Server 2019) directly in the site’s HSTS settings. On older versions as a custom response header.

Sources and documentation