Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is conditional logging in nginx?
Conditional logging in nginx means logging requests only when certain conditions are met, like logging errors but not successful requests.
Click to reveal answer
beginner
Which nginx directive is used to control conditional logging?
The access_log directive with a condition parameter controls conditional logging.
Click to reveal answer
intermediate
How do you disable logging for requests with status code 200 in nginx?
Use access_log /path/to/log combined if=$loggable; where $loggable is 0 for status 200, for example: map $status $loggable { 200 0; default 1; } and then access_log /path/to/log combined if=$loggable;
Click to reveal answer
intermediate
What is the purpose of the map directive in conditional logging?
The map directive creates a variable based on conditions, which can be used to decide if logging should happen.
Click to reveal answer
intermediate
Can you log only error responses (status 400 and above) in nginx?
Yes, by using a map to set a variable to 1 for status codes 400 and above, then using access_log with if to log only when that variable is 1.
Click to reveal answer
Which directive controls logging in nginx?
Aaccess_log
Berror_log
Clog_format
Dserver_log
✗ Incorrect
The access_log directive controls logging of client requests.
How do you disable logging for certain requests in nginx?
D. Missing $ before loggable in access_log condition
Solution
Step 1: Check variable usage in access_log
Variables must be prefixed with $ in conditions, so if=loggable is wrong.
Step 2: Confirm correct syntax
Correct syntax is if=$loggable to reference the variable properly.
Final Answer:
Missing $ before loggable in access_log condition -> Option D
Quick Check:
Variables need $ prefix in if= [OK]
Hint: Always prefix variables with $ in if= conditions [OK]
Common Mistakes:
Omitting $ before variable in if= condition
Miswriting map syntax
Assuming $status cannot be used in map
5. You want to log all requests except those with user agent containing "Googlebot". Which configuration correctly implements this conditional logging?