Recall & Review
beginner
What is the purpose of the
map directive in nginx?The
map directive creates a new variable whose value depends on the value of another variable. It helps to simplify complex conditional logic by mapping input values to output values.Click to reveal answer
beginner
How do you define a basic
map block in nginx?You define it with
map $input_variable $output_variable { ... } where inside the braces you list input values and their corresponding output values.Click to reveal answer
intermediate
What happens if no match is found in a
map directive?If no match is found, the
map directive uses the value defined by the default keyword if provided, or an empty string otherwise.Click to reveal answer
intermediate
Can the
map directive use regular expressions for matching?Yes, the
map directive supports regular expression matching by prefixing the pattern with ~ for case-sensitive or ~* for case-insensitive matching.Click to reveal answer
beginner
Where should the
map directive be placed in the nginx configuration?The
map directive must be placed in the http context, outside of server or location blocks.Click to reveal answer
What does the
map directive in nginx do?✗ Incorrect
The
map directive creates a new variable based on the value of another variable.Where must the
map directive be placed in nginx config?✗ Incorrect
The
map directive must be placed in the http context.How do you specify a default value in a
map directive?✗ Incorrect
The
default keyword sets the value if no other match is found.Which prefix is used for case-insensitive regex matching in
map?✗ Incorrect
The
~* prefix is used for case-insensitive regex matching.What will be the output variable if no match and no default is set in
map?✗ Incorrect
If no match and no default, the output variable is an empty string.
Explain how the
map directive works in nginx and give an example of its usage.Think about how you can assign values conditionally without if statements.
You got /4 concepts.
Describe where and why you would use the
map directive in an nginx configuration.Consider how nginx handles variables and conditions.
You got /4 concepts.