0
0
Nginxdevops~10 mins

Basic authentication in Nginx - Interactive Code Practice

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

Complete the code to enable basic authentication in the server block.

Nginx
server {
    listen 80;
    location / {
        auth_basic [1];
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
}
Drag options to blanks, or click blank then click option'
A"Restricted Area"
Boff
Callow all
Ddeny all
Attempts:
3 left
💡 Hint
Common Mistakes
Using off disables authentication instead of enabling it.
Not using quotes around the realm string causes syntax errors.
2fill in blank
medium

Complete the code to specify the path to the password file for basic authentication.

Nginx
location /secure {
    auth_basic "Secure Area";
    auth_basic_user_file [1];
}
Drag options to blanks, or click blank then click option'
A/etc/nginx/.htpasswd
B/var/www/html/index.html
C/etc/passwd
D/usr/local/nginx/conf/nginx.conf
Attempts:
3 left
💡 Hint
Common Mistakes
Using the system's /etc/passwd file instead of the .htpasswd file.
Pointing to a directory or unrelated file causes errors.
3fill in blank
hard

Fix the error in the auth_basic directive to enable basic authentication.

Nginx
location /admin {
    auth_basic [1];
    auth_basic_user_file /etc/nginx/.htpasswd;
}
Drag options to blanks, or click blank then click option'
Aoff
Bnone
Ctrue
D"Admin Area"
Attempts:
3 left
💡 Hint
Common Mistakes
Using off disables authentication.
Using unquoted strings causes syntax errors.
4fill in blank
hard

Fill both blanks to configure basic authentication with a custom realm and password file.

Nginx
location /private {
    auth_basic [1];
    auth_basic_user_file [2];
}
Drag options to blanks, or click blank then click option'
A"Private Area"
B/etc/nginx/.htpasswd
C/var/www/html/.htpasswd
D"Public Area"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect path for the password file.
Not quoting the realm string.
5fill in blank
hard

Fill all three blanks to create a server block that listens on port 8080 and uses basic authentication with a custom realm and password file.

Nginx
server {
    listen [1];
    location /secure {
        auth_basic [2];
        auth_basic_user_file [3];
    }
}
Drag options to blanks, or click blank then click option'
A80
B"Secure Zone"
C/etc/nginx/.htpasswd
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using the default port 80 instead of 8080.
Not quoting the realm string.
Incorrect password file path.