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 the purpose of customizing log formats in nginx?
Customizing log formats in nginx helps you record exactly the information you need about requests, making it easier to analyze traffic, debug issues, and monitor performance.
Click to reveal answer
beginner
Which nginx directive is used to define a custom log format?
The log_format directive is used to define a custom log format in nginx.
Click to reveal answer
intermediate
How do you apply a custom log format to an access log in nginx?
You apply a custom log format by specifying its name in the access_log directive, like access_log /path/to/log custom_format_name;.
Click to reveal answer
beginner
What does the variable $remote_addr represent in nginx log formats?
$remote_addr represents the IP address of the client making the request.
Click to reveal answer
intermediate
Give an example of a simple custom log format that logs client IP, request method, and request URI.
The format is: $remote_addr - $remote_user [$time_local] "$request" $status. This means client IP, dash, user, time, request, and status code in order.
Step 2: Match format to options
Client IP - user [time] "request" status code correctly describes the order and content of the log entry.
Final Answer:
Client IP - user [time] "request" status code -> Option C
Quick Check:
Variables order matches Client IP - user [time] "request" status code [OK]
Hint: Match variables order exactly to format string [OK]
Common Mistakes:
Mixing order of variables
Confusing $remote_user with $remote_addr
Ignoring quotes around $request
4. You wrote this configuration:
log_format mylog $remote_addr - $request_uri
But nginx fails to start. What is the error?
medium
A. Missing semicolon at the end
B. Missing quotes around the log format string
C. Incorrect variable name $request_uri
D. log_format directive cannot be used in http block
Solution
Step 1: Check syntax requirements for log_format
The log_format directive must end with a semicolon (;).
Step 2: Identify the error in given config
The string lacks the terminating semicolon, causing a syntax error.
Final Answer:
Missing semicolon at the end -> Option A
Quick Check:
Semicolon terminates the directive [OK]
Hint: Every nginx directive ends with semicolon [OK]
Common Mistakes:
Forgetting quotes around format string
Using wrong variable names
Omitting semicolon
5. You want to log the client IP, request method, and response time in seconds with 3 decimal places. Which custom log_format definition achieves this?
hard
A. log_format timed '$remote_addr $request_method $request_time';
access_log /var/log/nginx/timed.log timed if=$request_time;
B. log_format timed '$remote_addr $request_method $request_time sec';
C. log_format timed '$remote_addr $request_method $request_time';
D. log_format timed '$remote_addr $request_method $request_time';
access_log /var/log/nginx/timed.log timed;
Solution
Step 1: Define log_format with required variables
Use $remote_addr for client IP, $request_method for method, and $request_time for response time with decimals.
Step 2: Apply the custom format in access_log
To activate the format, use access_log with the format name and log file path.