0
0
Nginxdevops~10 mins

Map directive for variable mapping 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 define a map that sets $cache_bypass to 1 when $arg_nocache is present.

Nginx
map $arg_nocache [1] {
    default 0;
    1 1;
}
Drag options to blanks, or click blank then click option'
A$cache_bypass_value
Bnocache_flag
C$nocache
D$cache_bypass
Attempts:
3 left
💡 Hint
Common Mistakes
Using the source variable instead of the target variable.
Omitting the dollar sign in variable names.
2fill in blank
medium

Complete the map directive to set $backend to 'server1' when $http_host is 'example.com'.

Nginx
map $http_host [1] {
    default backend_default;
    example.com server1;
}
Drag options to blanks, or click blank then click option'
A$server
B$backend
Cbackend
D$host_backend
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name without the dollar sign.
Using an unrelated variable name.
3fill in blank
hard

Fix the error in the map directive to correctly map $request_uri to $clean_uri by removing query strings.

Nginx
map $request_uri [1] {
    ~^(?<clean_uri>[^?]+) $clean_uri;
    default $request_uri;
}
Drag options to blanks, or click blank then click option'
A$clean_uri
Bclean_uri
C$uri_clean
D$clean
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign.
Using a different variable name than the capture group.
4fill in blank
hard

Fill both blanks to create a map that sets $is_mobile to '1' if $http_user_agent contains 'Mobile', else '0'.

Nginx
map $http_user_agent [1] {
    ~Mobile [2];
    default 0;
}
Drag options to blanks, or click blank then click option'
A$is_mobile
B1
Ctrue
D$mobile_flag
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name without a dollar sign.
Using 'true' instead of '1'.
5fill in blank
hard

Fill all three blanks to create a map that sets $env based on $host: 'prod' for 'example.com', 'dev' for 'dev.example.com', else 'test'.

Nginx
map $host [1] {
    example.com [2];
    dev.example.com [3];
    default test;
}
Drag options to blanks, or click blank then click option'
A$env
Bprod
Cdev
D$environment
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name without a dollar sign.
Mixing up the values for hosts.