0
0
Nginxdevops~30 mins

SNI for multiple SSL certificates in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
SNI for Multiple SSL Certificates in Nginx
📖 Scenario: You are managing a web server that hosts two different websites on the same IP address. Each website needs its own SSL certificate to keep user data safe. To do this, you will use Server Name Indication (SNI) in Nginx, which allows the server to present the correct SSL certificate based on the website the user wants to visit.
🎯 Goal: Set up Nginx to serve two websites with different SSL certificates using SNI. You will create the basic server blocks, add SSL certificate paths, and configure Nginx to use the correct certificate for each domain.
📋 What You'll Learn
Create two server blocks for domains example1.com and example2.com
Add SSL certificate and key file paths for each domain
Configure Nginx to use SNI to serve the correct certificate based on the requested domain
Test the configuration by printing the server names and SSL certificate paths
💡 Why This Matters
🌍 Real World
Web hosting providers and system administrators use SNI to host multiple secure websites on a single server IP address, saving resources and costs.
💼 Career
Knowing how to configure SNI in Nginx is essential for DevOps engineers and system administrators managing secure web servers.
Progress0 / 4 steps
1
Create basic server blocks for two domains
Create two server blocks in Nginx configuration for example1.com and example2.com listening on port 443 with SSL enabled. Use server_name example1.com; for the first and server_name example2.com; for the second.
Nginx
Need a hint?

Use server { ... } blocks with listen 443 ssl; and server_name directives for each domain.

2
Add SSL certificate and key paths for each server block
Inside each server block, add the SSL certificate and key file paths. For example1.com, use ssl_certificate /etc/ssl/example1.crt; and ssl_certificate_key /etc/ssl/example1.key;. For example2.com, use ssl_certificate /etc/ssl/example2.crt; and ssl_certificate_key /etc/ssl/example2.key;.
Nginx
Need a hint?

Add ssl_certificate and ssl_certificate_key directives inside each server block with the exact file paths.

3
Add a location block to serve a simple message
Inside each server block, add a location / block that returns a plain text message. For example1.com, return Welcome to example1.com. For example2.com, return Welcome to example2.com. Use return 200 'message'; syntax.
Nginx
Need a hint?

Use location / { return 200 'message'; } inside each server block to send a simple text response.

4
Print the server names and SSL certificate paths
Print the server names and their SSL certificate paths exactly as shown below to verify your configuration: example1.com uses /etc/ssl/example1.crt example2.com uses /etc/ssl/example2.crt
Nginx
Need a hint?

Use two print statements with the exact text to show the server names and certificate paths.