vim nginxLogRotate.sh
#!/bin/bash
log_path=/data/log/nginx

yesterday=$(date -d "yesterday" +%Y-%m-%d)

mv ${log_path}/access.log ${log_path}/access_${yesterday}.log
mv ${log_path}/error.log ${log_path}/error_${yesterday}.log

kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)

find ${log_path} -mtime +15 -name "*.*" -exec rm -rf {} \;

计划任务

crontab -e

0 0 * * * /bin/bash /home/work/nginxLogRotate.sh