Bird
Raised Fist0
Nginxdevops~10 mins

SNI for multiple SSL certificates in Nginx - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - SNI for multiple SSL certificates
Client connects to server
↓
Client sends hostname in TLS handshake (SNI)
↓
Server reads SNI hostname
↓
Server selects matching SSL certificate
↓
Server completes TLS handshake with selected cert
↓
Secure connection established
↓
Server serves content for requested hostname
The server uses the hostname sent by the client during TLS handshake (SNI) to pick the right SSL certificate and establish a secure connection.
Execution Sample
Nginx
server {
  listen 443 ssl;
  server_name example.com;
  ssl_certificate /etc/ssl/example.com.crt;
  ssl_certificate_key /etc/ssl/example.com.key;
}

server {
  listen 443 ssl;
  server_name test.com;
  ssl_certificate /etc/ssl/test.com.crt;
  ssl_certificate_key /etc/ssl/test.com.key;
}
Two server blocks listen on port 443 with SSL, each serving a different domain with its own SSL certificate using SNI.
Process Table
StepClient Hostname (SNI)Server ActionSSL Certificate SelectedConnection Outcome
1example.comReads SNI hostname 'example.com'/etc/ssl/example.com.crtTLS handshake completes with example.com cert
2test.comReads SNI hostname 'test.com'/etc/ssl/test.com.crtTLS handshake completes with test.com cert
3unknown.comReads SNI hostname 'unknown.com'Default or no matching certTLS handshake may fail or use default cert
4-No more connections-Execution stops
💡 No more client connections to process
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
Client Hostname (SNI)-example.comtest.comunknown.com-
Selected SSL Certificate-/etc/ssl/example.com.crt/etc/ssl/test.com.crtDefault or none-
Connection Status-SuccessSuccessFail or default-
Key Moments - 2 Insights
Why does the server need the client to send the hostname during TLS handshake?
Because the server uses the hostname from SNI to pick the correct SSL certificate before completing the handshake, as shown in execution_table steps 1 and 2.
What happens if the client sends a hostname that the server does not have a certificate for?
The server either uses a default certificate or the handshake fails, as seen in execution_table step 3 where 'unknown.com' has no matching cert.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which SSL certificate is selected when the client sends 'test.com'?
ADefault or no matching cert
B/etc/ssl/test.com.crt
C/etc/ssl/example.com.crt
DNo certificate selected
💡 Hint
Check the row where Client Hostname is 'test.com' in the execution_table.
At which step does the TLS handshake possibly fail due to no matching certificate?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look for the step with 'unknown.com' hostname in the execution_table.
If the server did not use SNI, what would happen when multiple SSL certificates are configured?
AServer picks the right certificate automatically
BServer rejects all connections
CServer uses only one certificate for all hostnames
DServer sends all certificates to client
💡 Hint
Think about why SNI is needed as explained in key_moments and concept_flow.
Concept Snapshot
SNI allows a server to use multiple SSL certificates on one IP.
Client sends hostname during TLS handshake.
Server reads hostname and selects matching certificate.
Without SNI, only one certificate can be used per IP.
Configured in nginx with multiple server blocks on port 443.
Each server block has its own ssl_certificate and ssl_certificate_key.
Full Transcript
When a client connects to a server using HTTPS, it sends the hostname it wants to reach during the TLS handshake using a feature called SNI. The server reads this hostname and chooses the correct SSL certificate to use for that connection. This allows one server IP to serve many domains securely with different certificates. In nginx, this is done by creating multiple server blocks listening on port 443 with ssl enabled, each specifying its own server_name and SSL certificate files. If the client sends a hostname that the server does not recognize, the server may use a default certificate or the handshake may fail. Without SNI, the server can only use one certificate per IP address, limiting hosting multiple secure sites on the same IP.

Practice

(1/5)
1. What is the main purpose of SNI (Server Name Indication) in nginx when using multiple SSL certificates?
easy
A. To allow multiple SSL certificates on a single IP address by selecting the correct certificate based on the requested domain name.
B. To enable HTTP/2 protocol support for faster website loading.
C. To redirect all HTTP traffic to HTTPS automatically.
D. To combine multiple SSL certificates into one file for easier management.

Solution

  1. Step 1: Understand what SNI does

    SNI allows the server to present different SSL certificates depending on the domain name requested by the client.
  2. Step 2: Relate SNI to nginx configuration

    In nginx, SNI lets you use multiple server blocks with different SSL certificates on the same IP and port.
  3. Final Answer:

    To allow multiple SSL certificates on a single IP address by selecting the correct certificate based on the requested domain name. -> Option A
  4. Quick Check:

    SNI = Multiple SSL certs on one IP [OK]
Hint: SNI matches domain to SSL cert on same IP [OK]
Common Mistakes:
  • Confusing SNI with HTTP/2 support
  • Thinking SNI merges certificates into one
  • Assuming SNI automatically redirects HTTP to HTTPS
2. Which of the following nginx server block snippets correctly enables SNI for two domains with separate SSL certificates?
easy
A. server { listen 80; server_name example.com example.org; ssl_certificate /etc/ssl/all.crt; ssl_certificate_key /etc/ssl/all.key; }
B. server { listen 443 ssl; server_name example.com; ssl_certificate /etc/ssl/example.com.crt; ssl_certificate_key /etc/ssl/example.com.key; } server { listen 443 ssl; server_name example.org; ssl_certificate /etc/ssl/example.org.crt; ssl_certificate_key /etc/ssl/example.org.key; }
C. server { listen 443; server_name example.com; ssl_certificate /etc/ssl/example.com.crt; ssl_certificate_key /etc/ssl/example.com.key; } server { listen 443; server_name example.org; ssl_certificate /etc/ssl/example.org.crt; ssl_certificate_key /etc/ssl/example.org.key; }
D. server { listen 443 ssl; server_name example.com example.org; ssl_certificate /etc/ssl/example.com.crt; ssl_certificate_key /etc/ssl/example.com.key; }

Solution

  1. Step 1: Check listen directive for SSL

    Each server block must listen on port 443 with ssl enabled to serve HTTPS.
  2. Step 2: Verify separate server blocks for each domain

    server { listen 443 ssl; server_name example.com; ssl_certificate /etc/ssl/example.com.crt; ssl_certificate_key /etc/ssl/example.com.key; } server { listen 443 ssl; server_name example.org; ssl_certificate /etc/ssl/example.org.crt; ssl_certificate_key /etc/ssl/example.org.key; } has two server blocks, each with its own server_name and SSL cert/key, which is correct for SNI.
  3. Final Answer:

    server { listen 443 ssl; server_name example.com; ssl_certificate /etc/ssl/example.com.crt; ssl_certificate_key /etc/ssl/example.com.key; } server { listen 443 ssl; server_name example.org; ssl_certificate /etc/ssl/example.org.crt; ssl_certificate_key /etc/ssl/example.org.key; } -> Option B
  4. Quick Check:

    Separate server blocks + listen 443 ssl = correct SNI setup [OK]
Hint: Use separate server blocks with listen 443 ssl for each domain [OK]
Common Mistakes:
  • Omitting 'ssl' in listen directive on port 443
  • Combining multiple domains in one server block with one cert
  • Using port 80 for SSL configuration
3. Given this nginx configuration snippet, what will happen when a client requests https://example.net?
server {
  listen 443 ssl;
  server_name example.com;
  ssl_certificate /etc/ssl/example.com.crt;
  ssl_certificate_key /etc/ssl/example.com.key;
}

server {
  listen 443 ssl;
  server_name example.org;
  ssl_certificate /etc/ssl/example.org.crt;
  ssl_certificate_key /etc/ssl/example.org.key;
}
medium
A. The client will receive the SSL certificate for example.com because example.net is not configured.
B. The client will receive the SSL certificate for example.org as a fallback.
C. The connection will fail because example.net is not configured with SSL.
D. The client will receive a certificate error but connect to example.com.

Solution

  1. Step 1: Identify configured server names

    Only example.com and example.org have server blocks with SSL certificates.
  2. Step 2: Understand nginx default server behavior

    If a requested domain is not matched, nginx serves the default SSL server block, which is usually the first one defined (example.com here).
  3. Final Answer:

    The client will receive the SSL certificate for example.com because example.net is not configured. -> Option A
  4. Quick Check:

    Unmatched domain gets first SSL cert [OK]
Hint: Unmatched domains get first server block cert [OK]
Common Mistakes:
  • Assuming nginx picks a fallback cert arbitrarily
  • Thinking connection fails without explicit config
  • Believing client gets a certificate error immediately
4. You configured two server blocks for SNI but clients always get the same SSL certificate regardless of domain. What is the most likely cause?
medium
A. The SSL certificate files are corrupted.
B. Both server blocks are missing the ssl parameter in the listen directive.
C. The server_name directives are identical in both server blocks.
D. The firewall is blocking port 443.

Solution

  1. Step 1: Check server_name directives

    If the server_name directives are identical in both blocks, nginx cannot distinguish between domains using SNI.
  2. Step 2: Understand effect on SNI

    SNI relies on unique server_name matches to select the correct server block and certificate. Identical names cause all requests to use the first block (default), resulting in the same certificate.
  3. Final Answer:

    The server_name directives are identical in both server blocks. -> Option C
  4. Quick Check:

    Identical server_name = always first cert [OK]
Hint: Unique server_name per block required for SNI [OK]
Common Mistakes:
  • Missing 'ssl' parameter in listen directive
  • The SSL certificate files are corrupted
  • The firewall is blocking port 443
5. You want to host three domains with different SSL certificates on one nginx server using SNI. Which configuration approach correctly ensures each domain uses its own certificate and nginx listens properly for HTTPS?
hard
A. Create three server blocks with listen 443; (without ssl), each with unique server_name and SSL certificates.
B. Use one server block with listen 443 ssl; and list all three domains in server_name, then specify one combined SSL certificate covering all domains.
C. Use one server block with listen 80; and redirect all traffic to HTTPS on port 443 with a single SSL certificate.
D. Create three separate server blocks, each with listen 443 ssl;, unique server_name, and corresponding ssl_certificate and ssl_certificate_key.

Solution

  1. Step 1: Understand SNI requires separate server blocks

    Each domain needs its own server block with listen 443 ssl; and its own SSL cert/key.
  2. Step 2: Verify correct listen and server_name usage

    Create three separate server blocks, each with listen 443 ssl;, unique server_name, and corresponding ssl_certificate and ssl_certificate_key. correctly uses three server blocks with SSL enabled on port 443 and unique domain names.
  3. Final Answer:

    Create three separate server blocks, each with listen 443 ssl, unique server_name, and corresponding SSL certificate and key. -> Option D
  4. Quick Check:

    Separate server blocks + listen 443 ssl + unique certs = correct SNI [OK]
Hint: One server block per domain with listen 443 ssl and cert [OK]
Common Mistakes:
  • Using one server block for multiple domains without SAN cert
  • Omitting 'ssl' in listen directive
  • Using port 80 for SSL traffic
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard