0
0
Nginxdevops~10 mins

Request/response transformation 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 set a custom header in the response.

Nginx
add_header X-Custom-Header [1];
Drag options to blanks, or click blank then click option'
A"MyValue"
BMyValue
C'MyValue'
DMyValue;
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to quote the header value causes syntax errors.
Using single quotes instead of double quotes may not work as expected.
2fill in blank
medium

Complete the code to rewrite the request URI to /newpath.

Nginx
rewrite ^[1] /newpath break;
Drag options to blanks, or click blank then click option'
A^/oldpath$
B/oldpath
C/oldpath$
D^/oldpath
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting anchors causes partial matches.
Using plain strings instead of regex patterns.
3fill in blank
hard

Fix the error in the proxy_set_header directive to forward the original Host header.

Nginx
proxy_set_header Host [1];
Drag options to blanks, or click blank then click option'
AHOST
B$host
C$Host
Dhost
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the dollar sign causes nginx to treat it as a literal string.
Using incorrect capitalization of variables.
4fill in blank
hard

Fill both blanks to set a response header only if the status is 404.

Nginx
if ($status [1] 404) {
    add_header X-Error [2];
}
Drag options to blanks, or click blank then click option'
A==
B!=
C"Not Found"
D"Error"
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == reverses the condition.
Not quoting the header value causes syntax errors.
5fill in blank
hard

Fill all three blanks to create a map that transforms status codes to messages.

Nginx
map $status $message {
    200 [1];
    404 [2];
    default [3];
}
Drag options to blanks, or click blank then click option'
A"OK"
B"Not Found"
C"Unknown"
D"Error"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the messages causes errors.
Using incorrect keys or missing the default case.