0
0
Nginxdevops~5 mins

Log rotation in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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.
Example configuration:
/var/log/nginx/access.log {
  daily
  missingok
  rotate 7
  compress
  delaycompress
  notifempty
  create 0640 www-data adm
  sharedscripts
  postrotate
    systemctl reload nginx > /dev/null 2>&1 || true
  endscript
}
Click to reveal answer
beginner
Why is it important to reload or restart nginx after log rotation?
Reloading nginx after log rotation makes nginx close the old log files and open new ones, so it continues logging correctly without losing data.
Click to reveal answer
What does the rotate 7 directive mean in a logrotate config?
ACreate 7 new log files
BRotate logs every 7 minutes
CKeep 7 old log files before deleting
DCompress logs 7 times
Which command is typically used inside postrotate to reload nginx?
Asystemctl reload nginx
Bnginx -s stop
Cservice nginx restart
Dkillall nginx
What happens if nginx is not reloaded after log rotation?
ANginx crashes
BNginx continues writing to old log files
CNginx creates new log files automatically
DNginx stops logging completely
Which of these is NOT a common logrotate option?
Acompress
Bdelaycompress
Crotate
Drestart
Where are nginx log files usually located on a Linux system?
A/var/log/nginx/
B/etc/nginx/logs/
C/usr/nginx/logs/
D/home/nginx/logs/
Explain how log rotation works for nginx logs and why it is important.
Think about what happens when logs grow too big and how nginx handles log files.
You got /4 concepts.
    Describe a basic logrotate configuration for nginx logs including key directives and scripts.
    Focus on the main parts of a logrotate config and how it interacts with nginx.
    You got /5 concepts.