Windows Server Operations Series

🪪 The Top 1% Hands-On for Using SNI on IIS to Run Multiple Domains' TLS Certificates on a Single IP Address

Introduction

This article is part of the Top 1% Series Complete Article Guide.

Prerequisite Knowledge

The Big Picture

sequenceDiagram
    participant C as Client
    participant S as IIS (a single IP address)
    C->>S: Begins the TLS handshake<br/>(ClientHello includes server name: app1.lab.local)
    Note over S: Looks at the SNI value and<br/>selects the certificate for app1.lab.local
    S->>C: Presents the certificate for app1.lab.local
    Note over C,S: After this, the site is finally decided<br/>by the HTTP request's Host header

Hands-On Steps

Step 1: Create Two Self-Signed Certificates

In PowerShell, create self-signed certificates for two different hostnames.

New-SelfSignedCertificate -DnsName "app1.lab.local" -CertStoreLocation "cert:\LocalMachine\My"
New-SelfSignedCertificate -DnsName "app2.lab.local" -CertStoreLocation "cert:\LocalMachine\My"

Note down each certificate’s thumbprint from certlm.msc (the local computer certificate store).

Step 2: Create Two IIS Sites

Create two independent websites, one for app1.lab.local and one for app2.lab.local.

New-Item "C:\inetpub\app1" -ItemType Directory
New-Item "C:\inetpub\app2" -ItemType Directory
"app1" | Out-File "C:\inetpub\app1\index.html"
"app2" | Out-File "C:\inetpub\app2\index.html"

Import-Module WebAdministration
New-Website -Name "App1Site" -PhysicalPath "C:\inetpub\app1" -Port 443 -HostHeader "app1.lab.local" -Ssl
New-Website -Name "App2Site" -PhysicalPath "C:\inetpub\app2" -Port 443 -HostHeader "app2.lab.local" -Ssl

Step 3: Bind SNI-Enabled Bindings to Each Certificate

This is the heart of this hands-on. In IIS Manager (or via netsh), assign each site’s HTTPS binding to its matching certificate, and enable the “Require Server Name Indication” checkbox.

$cert1 = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -match "app1.lab.local" }
$cert2 = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -match "app2.lab.local" }

netsh http add sslcert hostnameport=app1.lab.local:443 certhash=$($cert1.Thumbprint) certstorename=MY appid="{00000000-0000-0000-0000-000000000000}"
netsh http add sslcert hostnameport=app2.lab.local:443 certhash=$($cert2.Thumbprint) certstorename=MY appid="{00000000-0000-0000-0000-000000000000}"

This hostnameport specification is the real substance of an SNI-aware binding. Where a traditional (SNI-unaware) binding could only attach one certificate per “IP address:port” combination, a hostnameport-style binding can attach a different certificate per hostname, all under the same “IP address:port.”

Step 4: Confirm You Actually Get Different Certificates Back

From the client side, use openssl s_client’s -servername option to connect with a different hostname via SNI.

openssl s_client -connect <server's IP>:443 -servername app1.lab.local

Check the subject= line in the output and confirm the certificate for app1.lab.local comes back. Now connect to the exact same IP address and port, with a different -servername.

openssl s_client -connect <server's IP>:443 -servername app2.lab.local

Despite connecting to the exact same IP address and port, this time a different certificate for app2.lab.local should come back. You’ve confirmed, firsthand, that the server dynamically switches which certificate it returns, based solely on the SNI field in the ClientHello message — before encryption even begins.

What a Pro Sees Here (Top 1% Understanding)

The “Ordering” Contradiction Between TLS and HTTP That SNI Resolves

Before SNI existed, TLS carried a structural contradiction. The mechanism of routing to multiple sites on one IP address via HTTP’s Host header is information you can only read once TLS encryption has finished. But which certificate the server should present has to be decided the moment it starts that very encryption (the TLS handshake). In other words, a circular problem: “figuring out which site the request is for requires looking inside the HTTP content, but starting the TLS needed to see that content requires already knowing which site it’s for.” SNI breaks that cycle by including the hostname in plaintext (before encryption begins), right inside ClientHello, the very first message of the TLS handshake.

The Reality That Old Clients That Don’t Support SNI Still Exist

SNI is now widely deployed, but some extremely old OS/browser combinations (Internet Explorer on Windows XP, say) still exist that don’t support SNI at all. When such a client connects, the server never receives the SNI information, so it has no choice but to return the “default certificate” configured for that IP address and port (usually the certificate from whichever binding was registered first). The result is the client presented with an unintended domain’s certificate, triggering a certificate-name-mismatch warning. This constraint rarely matters in modern real-world work, but an environment that must support old clients can’t rely purely on an SNI-dependent setup — a constraint worth understanding.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. An unintended domain’s certificate comes back: Check with netsh http show sslcert whether that binding is correctly registered in hostnameport (SNI-aware) form.
  2. Only a specific client gets a certificate error: Check whether that client supports SNI (especially with an old OS or browser).
  3. A renewed certificate isn’t reflected: You need to delete the old binding with netsh http delete sslcert, then re-register it with the new certificate’s thumbprint.

Summary

Takeaways to Apply Today

  1. Before provisioning more IP addresses for multiple HTTPS domains, consider distinguishing certificates via SNI.
  2. In an environment that must support old clients, check the constraints of an SNI-dependent setup ahead of time.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).