logrotate

A complete script for logrotate. Rotate the log daily, restart the web server (here insinde a container) and copy the log to another location, someone else can analyze it later.

/var/log/nginx/nginx.access.log {
create
daily
rotate 7
compress
missingok
dateext
dateformat -%Y%m%d
compresscmd gzip
compressext .gz

# restart nginx in proxy container
postrotate
/usr/bin/docker exec -it nginx-proxy /etc/init.d/nginx reload > /dev/null 2>/dev/null
endscript

# copy the logs to angelfish nas share
lastaction
chown user1.group1 /var/log/nginx/nginx.access.log-$(date '+%Y%m%d').gz
cp /var/log/nginx/nginx.access.log-$(date '+%Y%m%d').gz /mnt/nas/nginx.access.log-$(date '+%Y%m%d').gz
endscript
}