0
0
Nginxdevops~20 mins

Access log configuration in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Access Log Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this nginx access log format?
Given the following nginx access log format configuration, what will be the exact log output for a request with client IP 192.168.1.10, method GET, URI /home, status 200, and response time 0.123 seconds?
Nginx
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
                '"$http_user_agent" $request_time';
access_log /var/log/nginx/access.log custom;
A192.168.1.10 - - [27/Apr/2024:12:00:00 +0000] "POST /home HTTP/1.1" 200 0 "-" "Mozilla/5.0" 0.123
B192.168.1.10 - - [27/Apr/2024:12:00:00 +0000] "GET /home HTTP/1.1" 404 0 "-" "Mozilla/5.0" 0.123
C192.168.1.10 - - [27/Apr/2024:12:00:00 +0000] "GET /home HTTP/1.1" 200 0 "-" "Mozilla/5.0" 0.123
D192.168.1.10 - - [27/Apr/2024:12:00:00 +0000] "GET /home HTTP/1.1" 200 512 "-" "Mozilla/5.0" 0.123
Attempts:
2 left
💡 Hint
Focus on the variables used in the log_format and the request details given.
Configuration
intermediate
2:00remaining
Which configuration disables access logging for a specific location?
You want to disable access logging only for requests to the /healthcheck location in nginx. Which configuration snippet achieves this?
A
location /healthcheck {
    error_log off;
}
B
location /healthcheck {
    access_log off;
}
C
location /healthcheck {
    access_log /dev/null;
}
D
location /healthcheck {
    access_log /var/log/nginx/health.log off;
}
Attempts:
2 left
💡 Hint
Look for the directive that explicitly disables access logging.
Troubleshoot
advanced
2:00remaining
Why are no access logs generated despite configuration?
An nginx server has this configuration: access_log /var/log/nginx/access.log combined; location /api { access_log off; } However, no logs are generated at all, even for requests outside /api. What is the most likely cause?
ANginx needs to be restarted after changing access_log directives to enable logging.
BThe combined log format is invalid and prevents logging.
CThe main access_log directive is overridden by the location block with access_log off, disabling logging globally.
DThe /var/log/nginx/access.log file has incorrect permissions preventing writing logs.
Attempts:
2 left
💡 Hint
Consider file system permissions and how nginx writes logs.
🔀 Workflow
advanced
2:00remaining
Order the steps to enable custom access logging in nginx
Put these steps in the correct order to enable a custom access log format and activate it in nginx.
A4,1,3,2
B1,4,3,2
C1,4,2,3
D4,3,1,2
Attempts:
2 left
💡 Hint
Think about editing config first, then defining format, then enabling it, then reloading.
Best Practice
expert
2:00remaining
Which is the best practice for managing access logs in a high-traffic nginx server?
For a high-traffic nginx server, which approach is best to manage access logs efficiently and avoid performance issues?
AUse asynchronous logging with a dedicated log processor and rotate logs frequently.
BDisable access logs completely to save disk space and CPU.
CWrite access logs to a single large file without rotation to simplify management.
DLog only error messages and ignore access logs to reduce overhead.
Attempts:
2 left
💡 Hint
Consider performance and log management best practices for busy servers.