0
0
Nginxdevops~10 mins

Conditional logging 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 disable logging for requests with status 404.

Nginx
map $status $loggable {
    404 [1];
    default 1;
}
Drag options to blanks, or click blank then click option'
A1
Bdisable
C0
Doff
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'off' or 'disable' instead of 0 disables logging incorrectly.
Setting 404 to 1 will enable logging instead of disabling it.
2fill in blank
medium

Complete the code to use the variable $loggable to control access log.

Nginx
access_log /var/log/nginx/access.log combined if=[1];
Drag options to blanks, or click blank then click option'
A$loggable
B$request_method
C$status
D$remote_addr
Attempts:
3 left
💡 Hint
Common Mistakes
Using $status directly in the 'if' condition does not work as expected.
Using unrelated variables like $request_method or $remote_addr.
3fill in blank
hard

Fix the error in the map block to correctly disable logging for 500 errors.

Nginx
map $status $loggable {
    500 [1];
    default 1;
}
Drag options to blanks, or click blank then click option'
Aoff
Bfalse
Cdisable
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'off' or 'disable' causes configuration errors.
Using 'false' is not recognized by nginx in map.
4fill in blank
hard

Fill both blanks to log only POST requests with status 200.

Nginx
map "$request_method:$status" $loggable {
    "[1]:[2]" 1;
    default 0;
}
Drag options to blanks, or click blank then click option'
APOST
BGET
C200
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' instead of 'POST' will log wrong requests.
Using '404' instead of '200' will log wrong status.
5fill in blank
hard

Fill all three blanks to log requests from 192.168.1.1 with status 403 or 404.

Nginx
map "$remote_addr:$status" $loggable {
    "[1]:[2]" 1;
    "[1]:[3]" 1;
    default 0;
}
Drag options to blanks, or click blank then click option'
A192.168.1.1
B403
C404
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using different IPs for the two entries.
Using status 200 instead of 403 or 404.