0
0
Nginxdevops~20 mins

Log rotation in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Log Rotation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Nginx logrotate configuration effect
Given this logrotate configuration snippet for nginx logs, what will happen after logrotate runs?
/var/log/nginx/*.log {
  daily
  missingok
  rotate 7
  compress
  delaycompress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    systemctl reload nginx > /dev/null 2>/dev/null || true
  endscript
}
ALogs are rotated weekly, keeping 7 uncompressed old logs, nginx is restarted after rotation.
BLogs are rotated daily, keeping 7 compressed old logs, nginx is reloaded after rotation.
CLogs are rotated daily, old logs are deleted immediately, nginx is stopped after rotation.
DLogs are rotated monthly, keeping 30 compressed old logs, nginx is reloaded before rotation.
Attempts:
2 left
💡 Hint
Look at the keywords 'daily', 'rotate 7', 'compress', and 'postrotate' commands.
Troubleshoot
intermediate
2:00remaining
Nginx logs not rotating as expected
You configured logrotate for nginx logs but notice logs are not rotating daily as expected. Which of these is the most likely cause?
AThe logrotate cron job is not running or disabled on the system.
BThe nginx service is running and does not allow log rotation.
CThe log files are empty, so logrotate refuses to rotate them.
DThe logrotate configuration file has 'weekly' instead of 'daily'.
Attempts:
2 left
💡 Hint
Check if the system is actually running the logrotate commands automatically.
Configuration
advanced
2:30remaining
Configure logrotate to keep logs for 14 days and compress immediately
Which logrotate configuration snippet correctly rotates nginx logs daily, keeps 14 compressed old logs, and compresses logs immediately after rotation?
A
/var/log/nginx/*.log {
  weekly
  rotate 14
  compress
  delaycompress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    systemctl reload nginx > /dev/null 2>/dev/null || true
  endscript
}
B
/var/log/nginx/*.log {
  daily
  rotate 14
  compress
  delaycompress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    systemctl reload nginx > /dev/null 2>/dev/null || true
  endscript
}
C
/var/log/nginx/*.log {
  daily
  rotate 7
  compress
  delaycompress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    systemctl reload nginx > /dev/null 2>/dev/null || true
  endscript
}
D
/var/log/nginx/*.log {
  daily
  rotate 14
  compress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    systemctl reload nginx > /dev/null 2>/dev/null || true
  endscript
}
Attempts:
2 left
💡 Hint
Immediate compression means no 'delaycompress' option.
Best Practice
advanced
2:00remaining
Recommended action after log rotation for nginx
After rotating nginx logs, what is the recommended action to ensure nginx writes to new log files?
ADo nothing; nginx automatically detects rotated logs.
BRestart the nginx service to apply log rotation changes.
CReload the nginx service to reopen log files without downtime.
DDelete old log files manually to free disk space.
Attempts:
2 left
💡 Hint
Consider how nginx handles open file descriptors after log rotation.
🧠 Conceptual
expert
2:30remaining
Understanding delaycompress in logrotate
What is the main reason to use the 'delaycompress' option in nginx logrotate configuration?
ATo delay compression until the next rotation cycle, ensuring the most recent rotated log remains uncompressed for immediate access.
BTo compress logs immediately after rotation to save disk space right away.
CTo delay log rotation until the log file reaches a certain size.
DTo prevent compression of any rotated logs permanently.
Attempts:
2 left
💡 Hint
Think about why you might want the newest rotated log to stay uncompressed temporarily.