What if you could secure many websites on one server without buying extra IP addresses?
Why SNI for multiple SSL certificates in Nginx? - Purpose & Use Cases
Imagine you run a website hosting service where many customers want their own secure websites on the same server. Without special tricks, you can only use one SSL certificate per IP address.
This means if you want to serve multiple secure sites, you need many IP addresses or complicated setups.
Manually assigning a unique IP address for each secure site is expensive and slow.
It also wastes IP addresses and makes managing certificates a headache.
Plus, users might see security warnings if the wrong certificate is served.
SNI (Server Name Indication) lets the server know which website the user wants before sending the SSL certificate.
This way, one IP address can serve many secure sites, each with its own certificate, without confusion.
server {
listen 1.2.3.4:443 ssl;
ssl_certificate /etc/ssl/site1.crt;
ssl_certificate_key /etc/ssl/site1.key;
server_name site1.com;
}
server {
listen 1.2.3.5:443 ssl;
ssl_certificate /etc/ssl/site2.crt;
ssl_certificate_key /etc/ssl/site2.key;
server_name site2.com;
}server {
listen 443 ssl;
server_name site1.com;
ssl_certificate /etc/ssl/site1.crt;
ssl_certificate_key /etc/ssl/site1.key;
}
server {
listen 443 ssl;
server_name site2.com;
ssl_certificate /etc/ssl/site2.crt;
ssl_certificate_key /etc/ssl/site2.key;
}SNI enables hosting many secure websites on a single IP address, saving resources and simplifying management.
A hosting company uses SNI to provide hundreds of customers with their own HTTPS websites on one server without needing hundreds of IP addresses.
Manual SSL setup needs one IP per certificate, which is costly and complex.
SNI lets one IP serve multiple SSL certificates by identifying the requested site early.
This makes hosting many secure sites easier, cheaper, and more scalable.
Practice
Solution
Step 1: Understand what SNI does
SNI allows the server to present different SSL certificates depending on the domain name requested by the client.Step 2: Relate SNI to nginx configuration
In nginx, SNI lets you use multipleserverblocks with different SSL certificates on the same IP and port.Final Answer:
To allow multiple SSL certificates on a single IP address by selecting the correct certificate based on the requested domain name. -> Option AQuick Check:
SNI = Multiple SSL certs on one IP [OK]
- Confusing SNI with HTTP/2 support
- Thinking SNI merges certificates into one
- Assuming SNI automatically redirects HTTP to HTTPS
Solution
Step 1: Check listen directive for SSL
Each server block must listen on port 443 withsslenabled to serve HTTPS.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 ownserver_nameand SSL cert/key, which is correct for SNI.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 BQuick Check:
Separate server blocks + listen 443 ssl = correct SNI setup [OK]
- Omitting 'ssl' in listen directive on port 443
- Combining multiple domains in one server block with one cert
- Using port 80 for SSL configuration
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;
}
Solution
Step 1: Identify configured server names
Only example.com and example.org have server blocks with SSL certificates.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).Final Answer:
The client will receive the SSL certificate for example.com because example.net is not configured. -> Option AQuick Check:
Unmatched domain gets first SSL cert [OK]
- Assuming nginx picks a fallback cert arbitrarily
- Thinking connection fails without explicit config
- Believing client gets a certificate error immediately
Solution
Step 1: Check server_name directives
If theserver_namedirectives are identical in both blocks, nginx cannot distinguish between domains using SNI.Step 2: Understand effect on SNI
SNI relies on uniqueserver_namematches to select the correct server block and certificate. Identical names cause all requests to use the first block (default), resulting in the same certificate.Final Answer:
Theserver_namedirectives are identical in both server blocks. -> Option CQuick Check:
Identical server_name = always first cert [OK]
- Missing 'ssl' parameter in listen directive
- The SSL certificate files are corrupted
- The firewall is blocking port 443
Solution
Step 1: Understand SNI requires separate server blocks
Each domain needs its own server block withlisten 443 ssl;and its own SSL cert/key.Step 2: Verify correct listen and server_name usage
Create three separate server blocks, each withlisten 443 ssl;, uniqueserver_name, and correspondingssl_certificateandssl_certificate_key. correctly uses three server blocks with SSL enabled on port 443 and unique domain names.Final Answer:
Create three separate server blocks, each with listen 443 ssl, unique server_name, and corresponding SSL certificate and key. -> Option DQuick Check:
Separate server blocks + listen 443 ssl + unique certs = correct SNI [OK]
- Using one server block for multiple domains without SAN cert
- Omitting 'ssl' in listen directive
- Using port 80 for SSL traffic
Ready to prove it?
Pass the test and this pattern moves unknown
