Bird
Raised Fist0
Nginxdevops~10 mins

SSL certificate installation in Nginx - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the SSL certificate file path in the nginx configuration.

Nginx
ssl_certificate [1];
Drag options to blanks, or click blank then click option'
A/etc/nginx/ssl/server.crt
B/etc/nginx/ssl/server.key
C/etc/nginx/ssl/ca_bundle.crt
D/etc/nginx/ssl/dhparam.pem
Attempts:
3 left
💡 Hint
Common Mistakes
Using the private key file path instead of the certificate file path.
Using the CA bundle file path in place of the certificate file.
2fill in blank
medium

Complete the code to specify the SSL certificate key file path in the nginx configuration.

Nginx
ssl_certificate_key [1];
Drag options to blanks, or click blank then click option'
A/etc/nginx/ssl/dhparam.pem
B/etc/nginx/ssl/ca_bundle.crt
C/etc/nginx/ssl/server.crt
D/etc/nginx/ssl/server.key
Attempts:
3 left
💡 Hint
Common Mistakes
Using the certificate file path instead of the private key file path.
Using the CA bundle or DH parameters file path here.
3fill in blank
hard

Fix the error in the nginx SSL configuration line to enable SSL on port 443.

Nginx
listen 443 [1];
Drag options to blanks, or click blank then click option'
Ahttp
Bssl
Chttps
Dtcp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'https' instead of 'ssl' in the listen directive.
Omitting the 'ssl' keyword, causing SSL not to work.
4fill in blank
hard

Fill both blanks to complete the nginx SSL configuration for the certificate and key files.

Nginx
ssl_certificate [1];
ssl_certificate_key [2];
Drag options to blanks, or click blank then click option'
A/etc/nginx/ssl/mydomain.crt
B/etc/nginx/ssl/mydomain.key
C/etc/nginx/ssl/server.key
D/etc/nginx/ssl/server.crt
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the certificate and key file paths.
Using default server files instead of your domain's files.
5fill in blank
hard

Fill all three blanks to complete the nginx SSL server block snippet with listen, certificate, and key directives.

Nginx
server {
    listen 443 [1];
    ssl_certificate [2];
    ssl_certificate_key [3];
}
Drag options to blanks, or click blank then click option'
Assl
B/etc/nginx/ssl/example.com.crt
C/etc/nginx/ssl/example.com.key
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'ssl' in the listen directive.
Mixing up certificate and key file paths.

Practice

(1/5)
1. What is the main purpose of installing an SSL certificate in nginx?
easy
A. To encrypt data between the user and the server
B. To speed up the website loading time
C. To block unwanted visitors
D. To increase server storage space

Solution

  1. Step 1: Understand SSL certificate purpose

    SSL certificates encrypt data to keep communication secure between users and servers.
  2. Step 2: Identify the correct purpose in nginx context

    In nginx, SSL certificates enable HTTPS, which encrypts data transfer.
  3. Final Answer:

    To encrypt data between the user and the server -> Option A
  4. Quick Check:

    SSL = encrypt data [OK]
Hint: SSL means secure data transfer over HTTPS [OK]
Common Mistakes:
  • Thinking SSL speeds up website
  • Confusing SSL with blocking visitors
  • Assuming SSL increases storage
2. Which of the following is the correct nginx directive to specify the SSL certificate file?
easy
A. ssl_key /etc/nginx/cert.pem;
B. ssl_certificate_file /etc/nginx/cert.pem;
C. ssl_certificate /etc/nginx/cert.pem;
D. ssl_cert /etc/nginx/cert.pem;

Solution

  1. Step 1: Recall nginx SSL certificate directive

    The correct directive to specify the SSL certificate file is ssl_certificate.
  2. Step 2: Check options for syntax correctness

    Only ssl_certificate /etc/nginx/cert.pem; uses the exact directive ssl_certificate with correct syntax.
  3. Final Answer:

    ssl_certificate /etc/nginx/cert.pem; -> Option C
  4. Quick Check:

    ssl_certificate = correct directive [OK]
Hint: Use ssl_certificate for cert file path in nginx [OK]
Common Mistakes:
  • Adding _file suffix to directive
  • Using ssl_key for certificate file
  • Misspelling ssl_certificate
3. Given this nginx server block snippet, what will happen when you restart nginx?
server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/certs/mycert.pem;
    ssl_certificate_key /etc/ssl/private/mykey.pem;
}
medium
A. nginx will fail to start due to missing ssl_protocols directive
B. nginx will start listening on port 443 with SSL enabled
C. nginx will listen on port 80 instead of 443
D. nginx will start but SSL will be disabled

Solution

  1. Step 1: Analyze the server block configuration

    The server listens on port 443 with SSL enabled using listen 443 ssl;. Certificate and key paths are provided.
  2. Step 2: Understand nginx behavior on restart

    With valid certificate and key paths, nginx will start listening on port 443 with SSL enabled. The ssl_protocols directive is optional and defaults to secure protocols.
  3. Final Answer:

    nginx will start listening on port 443 with SSL enabled -> Option B
  4. Quick Check:

    listen 443 ssl + certs = SSL enabled [OK]
Hint: listen 443 ssl + certs means SSL active [OK]
Common Mistakes:
  • Thinking ssl_protocols is mandatory
  • Assuming nginx defaults to port 80
  • Believing SSL disables without extra flags
4. You added SSL directives in nginx but get an error on restart: nginx: [emerg] PEM_read_bio_PrivateKey failed. What is the most likely cause?
medium
A. The private key file is missing or corrupted
B. The SSL certificate file path is incorrect
C. The listen directive is missing port 443
D. The ssl_certificate_key directive is misspelled

Solution

  1. Step 1: Understand the error message

    The error PEM_read_bio_PrivateKey failed means nginx cannot read the private key file properly.
  2. Step 2: Identify common causes

    This usually happens if the private key file is missing, corrupted, or has wrong permissions.
  3. Final Answer:

    The private key file is missing or corrupted -> Option A
  4. Quick Check:

    PEM_read_bio_PrivateKey error = private key issue [OK]
Hint: PEM_read_bio_PrivateKey error means private key problem [OK]
Common Mistakes:
  • Blaming certificate file instead of key
  • Ignoring file permissions
  • Assuming listen directive causes this error
5. You want nginx to redirect all HTTP traffic to HTTPS after installing SSL. Which configuration snippet correctly achieves this?
hard
A.
server {
    listen 80 ssl;
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
}
B.
server {
    listen 443 ssl;
    return 301 http://$host$request_uri;
}
C.
server {
    listen 443;
    return 301 http://$host$request_uri;
}
D.
server {
    listen 80;
    return 301 https://$host$request_uri;
}

Solution

  1. Step 1: Understand HTTP to HTTPS redirection

    To redirect HTTP (port 80) to HTTPS, nginx listens on port 80 and sends a 301 redirect to the HTTPS URL.
  2. Step 2: Check each option for correctness

    server {
        listen 80;
        return 301 https://$host$request_uri;
    }
    listens on port 80 and returns a 301 redirect to https://$host$request_uri, which is correct. Other options either redirect HTTPS to HTTP or misuse SSL on port 80.
  3. Final Answer:

    server { listen 80; return 301 https://$host$request_uri; } -> Option D
  4. Quick Check:

    listen 80 + return 301 https = redirect HTTP to HTTPS [OK]
Hint: Redirect HTTP on port 80 to HTTPS with return 301 [OK]
Common Mistakes:
  • Redirecting HTTPS to HTTP instead
  • Adding SSL to port 80 listener
  • Forgetting to use return 301 for redirect
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