Bird
Raised Fist0
Nginxdevops~20 mins

SSL directive configuration in Nginx - Mini Project: Build & Apply

Choose your learning style10 modes available
SSL Directive Configuration in Nginx
📖 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

  1. Step 1: Understand SSL certificate directive

    The directive to specify the SSL certificate file in nginx is ssl_certificate.
  2. 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.
  3. Final Answer:

    ssl_certificate -> Option D
  4. Quick Check:

    ssl_certificate = ssl_certificate [OK]
Hint: Remember: certificate file uses ssl_certificate directive [OK]
Common Mistakes:
  • Confusing ssl_certificate_key with ssl_certificate
  • Using incorrect directive names like ssl_key
  • Mixing certificate and key directives
2. Which of the following is the correct syntax to enable SSL in an nginx server block?
easy
A. ssl on;
B. enable ssl;
C. ssl_enable on;
D. ssl active;

Solution

  1. Step 1: Recall SSL enabling syntax in nginx

    In older nginx versions, SSL was enabled with ssl on; inside the server block.
  2. Step 2: Validate options

    Options A, B, and D are not valid nginx directives or syntax for enabling SSL.
  3. Final Answer:

    ssl on; -> Option A
  4. Quick Check:

    ssl on; = ssl on; [OK]
Hint: Use 'ssl on;' to enable SSL in nginx server block [OK]
Common Mistakes:
  • Using non-existent directives like enable ssl
  • Confusing directive names
  • Omitting the semicolon
3. Given this nginx SSL configuration snippet, what TLS versions are allowed?
ssl_protocols TLSv1.2 TLSv1.3;
medium
A. TLS 1.0, 1.1, 1.2, and 1.3 are allowed
B. Only TLS 1.2 and TLS 1.3 are allowed
C. Only TLS 1.3 is allowed
D. No TLS versions are allowed

Solution

  1. Step 1: Read ssl_protocols directive

    The directive ssl_protocols TLSv1.2 TLSv1.3; explicitly allows only TLS version 1.2 and 1.3.
  2. Step 2: Understand allowed TLS versions

    Older versions like TLS 1.0 and 1.1 are not included, so they are disallowed.
  3. Final Answer:

    Only TLS 1.2 and TLS 1.3 are allowed -> Option B
  4. Quick Check:

    ssl_protocols = TLSv1.2 and TLSv1.3 [OK]
Hint: ssl_protocols lists allowed TLS versions explicitly [OK]
Common Mistakes:
  • Assuming all TLS versions are allowed by default
  • Confusing ssl_protocols with ssl_ciphers
  • Ignoring missing older TLS versions
4. Identify the error in this nginx SSL configuration snippet:
ssl_certificate /etc/nginx/certs/server.crt
ssl_certificate_key /etc/nginx/certs/server.key;
medium
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

  1. Step 1: Check syntax for each directive

    Each nginx directive must end with a semicolon. The first line lacks a semicolon.
  2. Step 2: Verify other parts

    The file paths and directive names are correct, only the missing semicolon causes a syntax error.
  3. Final Answer:

    Missing semicolon after ssl_certificate directive -> Option A
  4. 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

  1. Step 1: Select TLS version

    Only TLS 1.3 is allowed by ssl_protocols TLSv1.3;, matching the requirement.
  2. 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.
  3. Final Answer:

    ssl_protocols TLSv1.3; ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'; -> Option C
  4. Quick Check:

    Only TLS 1.3 + strong ciphers = ssl_protocols TLSv1.3; ssl_ciphers 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'; [OK]
Hint: Use ssl_protocols TLSv1.3 and specify strong TLS 1.3 ciphers [OK]
Common Mistakes:
  • Allowing older TLS versions accidentally
  • Using 'ALL' cipher which is insecure
  • Mismatch between TLS version and cipher suite
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