0
0
Nginxdevops~5 mins

Map directive for variable mapping in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AMaps one variable's value to another variable's value
BDefines server listening ports
CSets up SSL certificates
DConfigures proxy pass
Where must the map directive be placed in nginx config?
AInside <code>location</code> block
BInside <code>server</code> block
CInside <code>events</code> block
DInside <code>http</code> block
How do you specify a default value in a map directive?
AUsing the <code>default</code> keyword
BUsing <code>else</code> keyword
CUsing <code>fallback</code> keyword
DUsing <code>catch</code> keyword
Which prefix is used for case-insensitive regex matching in map?
A~
B~*
C^~
D*~
What will be the output variable if no match and no default is set in map?
AError thrown
BInput variable value
CEmpty string
DNull value
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.