0
0
Nginxdevops~10 mins

Log rotation in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the log file path in the nginx configuration.

Nginx
access_log [1];
Drag options to blanks, or click blank then click option'
A/var/log/nginx/access.log
B/etc/nginx/nginx.conf
C/tmp/nginx.log
D/usr/share/nginx/html
Attempts:
3 left
💡 Hint
Common Mistakes
Using the configuration file path instead of the log file path.
Using a directory path instead of a file path.
2fill in blank
medium

Complete the command to reload nginx after log rotation.

Nginx
sudo systemctl [1] nginx
Drag options to blanks, or click blank then click option'
Areload
Bstop
Crestart
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using stop or restart causes downtime.
Using status does not reload configuration.
3fill in blank
hard

Fix the error in the logrotate configuration snippet for nginx logs.

Nginx
/var/log/nginx/*.log {
    daily
    missingok
    rotate [1]
    compress
    delaycompress
    notifempty
    create 0640 www-data adm
    sharedscripts
    postrotate
        /bin/systemctl reload nginx > /dev/null 2>&1 || true
    endscript
}
Drag options to blanks, or click blank then click option'
A5
Breload
Crestart
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands like reload or restart instead of a number.
Omitting the rotate count.
4fill in blank
hard

Fill both blanks to complete the logrotate postrotate script for nginx.

Nginx
/var/log/nginx/*.log {
    postrotate
        [1] nginx [2] > /dev/null 2>&1 || true
    endscript
}
Drag options to blanks, or click blank then click option'
Ainvoke-rc.d
Breload
Crestart
Dservice
Attempts:
3 left
💡 Hint
Common Mistakes
Using restart causes downtime.
Using service instead of invoke-rc.d in some systems.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps log file names to their sizes if size is greater than 0.

Nginx
log_sizes = [1]: [2] for [1] in [3] if os.path.getsize([1]) > 0
Drag options to blanks, or click blank then click option'
Alog
Bos.path.getsize(log)
Clogs
Dfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not filtering files with size > 0.