0
0
Nginxdevops~10 mins

Access log configuration 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 enable access logging in nginx.

Nginx
access_log [1];
Drag options to blanks, or click blank then click option'
A/etc/nginx/nginx.conf
B/var/log/nginx/access.log
C/usr/share/nginx/html
D/var/log/nginx/error.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using the error log path instead of the access log path.
Specifying a directory instead of a file path.
2fill in blank
medium

Complete the code to disable access logging in nginx.

Nginx
access_log [1];
Drag options to blanks, or click blank then click option'
Aoff
B/var/log/nginx/access.log
Con
D/var/log/nginx/error.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'off' to disable logging.
Providing a file path when intending to disable logging.
3fill in blank
hard

Fix the error in the access log format definition.

Nginx
log_format main '[1]';
Drag options to blanks, or click blank then click option'
A$remote_addr $remote_user $time_local $request $status $body_bytes_sent $http_referer $http_user_agent
Bremote_addr - remote_user [time_local] "request" status body_bytes_sent "http_referer" "http_user_agent"
C$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"
D$remote_addr - $remote_user $time_local $request $status $body_bytes_sent $http_referer $http_user_agent
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar signs before variables.
Missing quotes or brackets around parts of the log format.
4fill in blank
hard

Fill both blanks to configure nginx to use the custom log format and specify the log file.

Nginx
access_log [1] [2];
Drag options to blanks, or click blank then click option'
A/var/log/nginx/custom_access.log
Bmain
Cdefault
D/var/log/nginx/access.log
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of file path and format name.
Using the default log file instead of the custom one.
5fill in blank
hard

Fill all three blanks to create a conditional access log that logs only requests with status code 404.

Nginx
map $status $log_404 {
    default 0;
    [1] 1;
}

access_log [2] [3] if=$log_404;
Drag options to blanks, or click blank then click option'
A404
B/var/log/nginx/404.log
Cmain
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong status code in the map block.
Not using the if condition in access_log.
Mixing up the log file path and format name.