配置nginx日志切割功能

1.查看日志
ll /usr/local/nginx/logs/access.log
2.编写切割日志的脚本
vim /opt/cut_nginx_log.sh
#!/bin/bash
#cut_nginx_log.sh

datetime=$(date -d "-1 day" "+%Y%m%d")
log_path="/usr/local/nginx/logs"
pid_path="/usr/local/nginx/logs/nginx.pid"
[ -d $log_path/backup ] || mkdir -p $log_path/backup
if [ -f $pid_path ]
then
 mv $log_path/access.log $log_path/backup/access.log-$datetime
 kill -USR1 $(cat $pid_path)
 find $log_path/backup -mtime +30 | xargs rm -f
else
 echo " Error,Nginx is not working!" | tee -a /var/log/massages
fi
3.设置一个周期性的计划任务
crontab -e
0 0 * * *  /opt/cut_nginx_log.sh
posted @ 2019-09-17 16:33  Joshua¥A¥  阅读(148)  评论(0编辑  收藏  举报