📖 Scenario: You are setting up a secure website using Nginx web server. To protect your users' data, you need to configure SSL (Secure Sockets Layer) directives properly in your Nginx configuration file.This project will guide you step-by-step to create a basic SSL configuration for your website.
🎯 Goal: Build a simple Nginx server block configuration that enables SSL using the correct directives and paths to certificate files.
📋 What You'll Learn
Create a server block listening on port 443
Add SSL certificate and key file paths
Enable SSL protocol and specify TLS version
Print the final server block configuration
💡 Why This Matters
🌍 Real World
Web servers use SSL to encrypt data between the server and users, protecting sensitive information like passwords and credit card numbers.
💼 Career
Knowing how to configure SSL in Nginx is essential for DevOps engineers and system administrators to secure web applications.
Progress0 / 4 steps
1
Create the basic server block
Create a variable called nginx_config and assign it a string containing the basic Nginx server block listening on port 443 with server_name set to example.com.
Nginx
Hint
Use triple quotes or escape newlines to create a multi-line string for the server block.
2
Add SSL certificate and key file paths
Add the SSL certificate and key file directives inside the nginx_config string. Use ssl_certificate /etc/ssl/certs/example.crt; and ssl_certificate_key /etc/ssl/private/example.key; exactly.
Nginx
Hint
Place the SSL directives inside the server block, each on its own line.
3
Enable SSL protocols and specify TLS version
Add the directives ssl_protocols TLSv1.2 TLSv1.3; and ssl_prefer_server_ciphers on; inside the nginx_config string to specify TLS versions and cipher preference.
Nginx
Hint
These directives help ensure your server uses modern and secure SSL protocols.
4
Print the final Nginx SSL configuration
Write a print statement to display the full nginx_config string.
Nginx
Hint
Use print(nginx_config) to show the full configuration.
Practice
(1/5)
1. Which nginx directive is used to specify the SSL certificate file for HTTPS?
easy
A. ssl_key_certificate
B. ssl_key
C. ssl_cert_file
D. ssl_certificate
Solution
Step 1: Understand SSL certificate directive
The directive to specify the SSL certificate file in nginx is ssl_certificate.
Step 2: Compare options with correct syntax
Options B, C, and D are incorrect because they are not valid nginx directives for SSL certificate files.
A. Missing semicolon after ssl_certificate directive
B. Wrong file path for ssl_certificate_key
C. ssl_certificate_key directive is misspelled
D. ssl_certificate directive should not have a file path
Solution
Step 1: Check syntax for each directive
Each nginx directive must end with a semicolon. The first line lacks a semicolon.
Step 2: Verify other parts
The file paths and directive names are correct, only the missing semicolon causes a syntax error.
Final Answer:
Missing semicolon after ssl_certificate directive -> Option A
Quick Check:
Every directive ends with ; [OK]
Hint: Always end nginx directives with a semicolon [OK]
Common Mistakes:
Forgetting semicolons at line ends
Assuming file paths are incorrect without checking
Misspelling directive names
5. You want to configure nginx to use a strong cipher suite and only TLS 1.3. Which configuration snippet achieves this securely?
hard
A. ssl_protocols TLSv1.2;
ssl_ciphers 'TLS_AES_128_GCM_SHA256';
B. ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'HIGH:!aNULL:!MD5';
C. ssl_protocols TLSv1.3;
ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256';
D. ssl_protocols TLSv1.3;
ssl_ciphers 'ALL';
Solution
Step 1: Select TLS version
Only TLS 1.3 is allowed by ssl_protocols TLSv1.3;, matching the requirement.
Step 2: Choose strong cipher suites
ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'; uses strong TLS 1.3 ciphers explicitly. Other options either allow older TLS versions, use insecure cipher lists, or use generic 'ALL' which is insecure.
Final Answer:
ssl_protocols TLSv1.3; ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'; -> Option C