Configure logrotate d Debian / Ubuntu. log rotation

Logrotate – a program for managing log files, automatically archives, removes, cleans them.

Installation:
# Aptitude install logrotate

Configuration files are in /etc/logrotate.d/
Example configuration log rotation for nginx:
/var/log/nginx/*.log {

weekly
# Rotated once a week

missingok
# No file is not an error

rotate 52
# Saves the last 52 rotated file

compress
# Compress the file is rotated

delaycompress
# Compress the previous file with the following rotation

notifempty
# Does not handle empty files

create 640 root adm
# Immediately after rotation to create an empty file with the specified user rights and

sharedscripts
# Scripts prerotate / postrotate will be performed only once regardless of the number of magazines that correspond to a given pattern
postrotate

# Script will be executed immediately after the rotation
[! -f /var/run/nginx.pid] || kill -USR1 cat / var / run / nginx.pid
endscript
}

Check how everything will work (nothing is created or removed, it only checks):
# Logrotate -d /etc/logrotate.d/nginx

If everything is OK, you can start the rotation:
# Logrotate -v -f /etc/logrotate.d/nginx