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 log rotation in the context of nginx?
Log rotation is the process of renaming and archiving old log files and creating new ones to prevent logs from growing too large and consuming too much disk space.
Click to reveal answer
beginner
Which tool is commonly used to automate log rotation for nginx logs on Linux systems?
The logrotate tool is commonly used to automate log rotation for nginx logs on Linux systems.
Click to reveal answer
intermediate
What is the purpose of the postrotate script in a logrotate configuration for nginx?
The postrotate script runs commands after rotating logs, usually to tell nginx to reopen its log files so it writes to the new log files.
Click to reveal answer
intermediate
Show a simple logrotate configuration snippet for nginx access logs.
A. Logs rotate daily, delete all old logs, and nginx stops
B. Logs rotate weekly, keep 7 uncompressed files, and nginx restarts
C. Logs never rotate because of syntax error
D. Logs rotate daily, keep 7 old compressed files, and nginx reloads after rotation
Solution
Step 1: Analyze rotation frequency and retention
The daily directive means logs rotate every day. rotate 7 keeps 7 old log files.
Step 2: Check compression and reload
compress compresses old logs, delaycompress delays compression by one cycle. postrotate runs nginx -s reload to reopen logs.
Final Answer:
Logs rotate daily, keep 7 old compressed files, and nginx reloads after rotation -> Option D
Quick Check:
Daily rotate + 7 files + reload nginx = C [OK]
Hint: Look for 'daily', 'rotate 7', and 'postrotate nginx -s reload' [OK]
Common Mistakes:
Confusing daily with weekly rotation
Ignoring compression directives
Assuming nginx restarts instead of reloads
4. You configured logrotate for nginx but notice logs are not rotating. Which is the most likely cause?
medium
A. The log file path in logrotate config is incorrect
B. The compress directive is missing
C. The rotate number is set to 0
D. The postrotate script does not reload nginx
Solution
Step 1: Check log file path correctness
If the log file path in the logrotate config does not match actual nginx log locations, rotation won't happen.
Step 2: Evaluate other options
Not reloading nginx delays log reopening but rotation still occurs. rotate 0 disables rotation but is rare. Missing compress only affects compression, not rotation.
Final Answer:
The log file path in logrotate config is incorrect -> Option A
Quick Check:
Wrong log path = no rotation [OK]
Hint: Verify log file paths in config match actual nginx logs [OK]
Common Mistakes:
Assuming missing reload stops rotation
Thinking compression affects rotation
Ignoring log file path accuracy
5. You want to rotate nginx logs only when they reach 100MB size, keep 5 backups, compress old logs, and reload nginx smoothly. Which logrotate config snippet achieves this?
hard
A. /var/log/nginx/*.log {
size 100M
rotate 5
compress
missingok
notifempty
sharedscripts
postrotate
nginx -s reload
endscript
}