Challenge - 5 Problems
Map Directive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of Nginx map directive with simple variable mapping
Given the following Nginx configuration snippet, what will be the value of the variable
$color when the request URI is /blue?Nginx
map $uri $color {
default red;
/blue blue;
/green green;
}Attempts:
2 left
💡 Hint
The
map directive assigns values based on matching keys; if no match, it uses default.✗ Incorrect
The
map directive checks the $uri. Since the URI is /blue, it matches the key /blue and assigns blue to $color.🧠 Conceptual
intermediate1:30remaining
Purpose of the Nginx map directive
What is the primary purpose of the Nginx
map directive?Attempts:
2 left
💡 Hint
Think about how you can assign values dynamically based on another variable's value.
✗ Incorrect
The
map directive creates a new variable whose value depends on the value of another variable, allowing conditional logic in configuration.❓ Configuration
advanced2:30remaining
Correct Nginx map syntax for IP-based access control
Which of the following Nginx
map configurations correctly sets $allowed to 1 for IP 192.168.1.100 and 0 for all others?Attempts:
2 left
💡 Hint
Check the syntax for key-value pairs inside the map block.
✗ Incorrect
Option A uses the correct syntax: key and value separated by space and ending with semicolon. Other options have syntax errors.
❓ Troubleshoot
advanced3:00remaining
Troubleshooting unexpected variable value in Nginx map
You have this map directive:
map $http_user_agent $is_mobile {
default 0;
~*Mobile 1;
}
But $is_mobile is always 0 even when accessing from a mobile browser. What is the most likely cause?Attempts:
2 left
💡 Hint
Consider if the variable used in the map has the expected value during request processing.
✗ Incorrect
If
$http_user_agent is empty or missing, the regex match will never succeed, so $is_mobile stays at default 0.🔀 Workflow
expert3:00remaining
Order of evaluation in Nginx map directive with overlapping keys
Consider this map directive:
map $uri $page_type {
/about about_page;
~^/about/us about_us_page;
default other_page;
}
What will be the value of $page_type for the request URI /about/us?Attempts:
2 left
💡 Hint
The map directive evaluates keys in the order they appear; the first matching key wins.
✗ Incorrect
The map directive checks keys in the order they appear. The URI '/about/us' does not exactly match '/about', but matches the regex '~^/about/us', so $page_type is set to 'about_us_page'.