创建脚本 vi /root/nginx_log.sh
#!/bin/bash
##定义
logs_path="/var/log/nginx/"
pid_path="/var/run/nginx.pid"
itime=$(date -d yesterday "+%Y%m%d")
##重名
mv ${logs_path}access.log ${logs_path}access_${itime}.log
mv ${logs_path}error.log ${logs_path}error_${itime}.log
##定期删除
find ${logs_path} -mtime +7 -exec rm -f {} \;
##重置日志
kill -USR1 $(cat ${pid_path})
设置计划任务
crontab -e
0 0 * * * root /root/nginx_log.sh