Basic Authentication is a simple way to protect web pages by asking users for a username and password before allowing access.
Click to reveal answer
beginner
Which nginx directive is used to enable Basic Authentication?
The auth_basic directive enables Basic Authentication in nginx.
Click to reveal answer
intermediate
What file format does nginx use to store usernames and passwords for Basic Authentication?
Nginx uses a password file created by the htpasswd tool, which stores usernames and encrypted passwords.
Click to reveal answer
intermediate
How do you create a password file for Basic Authentication?
Use the command htpasswd -c /path/to/.htpasswd username to create a new password file and add a user.
Click to reveal answer
beginner
What happens if a user enters wrong credentials in Basic Authentication?
Nginx responds with a 401 Unauthorized status and asks the user to enter the correct username and password again.
Click to reveal answer
Which directive enables Basic Authentication in nginx?
Aauth_user
Bbasic_auth
Cauth_basic
Duser_auth
✗ Incorrect
The correct directive to enable Basic Authentication in nginx is auth_basic.
What tool is commonly used to create the password file for nginx Basic Authentication?
Ahtpasswd
Bpasswdgen
Cnginxpass
Dauthgen
✗ Incorrect
The htpasswd tool is used to create and manage password files for Basic Authentication.
What HTTP status code does nginx return when Basic Authentication fails?
A403 Forbidden
B401 Unauthorized
C404 Not Found
D500 Internal Server Error
✗ Incorrect
Nginx returns a 401 Unauthorized status code when authentication fails.
Where do you specify the path to the password file in nginx configuration?
Aauth_basic_user_file
Bauth_basic_file
Cauth_basic_user_path
Dauth_user_file
✗ Incorrect
The directive auth_user_file specifies the path to the password file.
What is the purpose of the auth_basic directive's value?
AIt sets the authentication realm shown to users
BIt sets the username
CIt disables authentication
DIt sets the password file path
✗ Incorrect
The value of auth_basic sets the authentication realm, a message shown in the login prompt.
Explain how to set up Basic Authentication in nginx from creating the password file to configuring nginx.
Think about the steps from user creation to nginx config.
You got /4 concepts.
Describe what happens when a user tries to access a protected page with Basic Authentication enabled.
Focus on the interaction between user and server.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of basic authentication in nginx?
easy
A. To speed up the website loading time
B. To encrypt all website traffic automatically
C. To require users to enter a username and password before accessing content
D. To block all users except the server admin
Solution
Step 1: Understand basic authentication purpose
Basic authentication prompts users for a username and password to restrict access.
Step 2: Compare options
Only To require users to enter a username and password before accessing content describes this login prompt function; others describe unrelated features.
Final Answer:
To require users to enter a username and password before accessing content -> Option C
Quick Check:
Basic authentication = login prompt [OK]
Hint: Basic auth means login prompt for access control [OK]
Common Mistakes:
Confusing basic auth with encryption
Thinking it speeds up the site
Assuming it blocks all users except admin
2. Which nginx directive is used to enable basic authentication in a server block?
easy
A. auth_basic_user_file
B. auth_user_file
C. basic_auth_enable
D. auth_basic
Solution
Step 1: Identify the directive for enabling basic auth
The directive auth_basic enables basic authentication and sets the login prompt message.
Step 2: Check other directives
auth_basic_user_file is incorrect; the correct directive for the password file is auth_basic_user_file but the enabling directive is auth_basic.
Final Answer:
auth_basic -> Option D
Quick Check:
Enable basic auth = auth_basic [OK]
Hint: Enable basic auth with auth_basic directive [OK]