0
0
Nginxdevops~10 mins

Log format customization 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 custom log format named 'main'.

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
B$remote_addr $request_time $status
C$host $remote_addr $request
D$status $body_bytes_sent $request_time
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a format missing $remote_addr or $request
Using incomplete log variables
2fill in blank
medium

Complete the code to set the access log to use the custom format 'main'.

Nginx
access_log /var/log/nginx/access.log [1];
Drag options to blanks, or click blank then click option'
Acustom
Bcombined
Cdefault
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'combined' which is a predefined format
Using undefined format names
3fill in blank
hard

Fix the error in the log_format directive to correctly include the request time.

Nginx
log_format timed '$remote_addr - $remote_user [$time_local] "$request" [1] $status';
Drag options to blanks, or click blank then click option'
A$requesttime
B$request_time
C$time_request
D$time_local
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names like $time_request
Confusing $time_local with request time
4fill in blank
hard

Fill both blanks to create a log format that logs client IP and user agent.

Nginx
log_format client_info '[1] - "$http_user_agent" [2]';
Drag options to blanks, or click blank then click option'
A$remote_addr
B$remote_user
C$request
D$status
Attempts:
3 left
💡 Hint
Common Mistakes
Using $request or $status instead of user info
Mixing variable order
5fill in blank
hard

Fill all three blanks to define a log format that logs the method, URI, and status code.

Nginx
log_format method_uri_status '[1] [2] [3]';
Drag options to blanks, or click blank then click option'
A$request_method
B$request_uri
C$status
D$remote_addr
Attempts:
3 left
💡 Hint
Common Mistakes
Including $remote_addr instead of status
Mixing variable order