当请求上来的时候nginx的日志是不个不容小觑的文件,它能增长到令人发指的地步,硬盘占满也是早晚的事
要切割的日志
access.log 和 error.log,目录 /home/nginx/logs/ (自己Nginx的安装目录)
日志切割脚本
#!/bin/bash year=`date +%Y` month=`date +%m` day=`date +%d` logs_backup_path="/home/nginx/logs_backup/$year$month" #日志存储路径 logs_path="/home/nginx/logs/" #要切割的日志路径 logs_access="access" #要切割的日志 logs_error="error" pid_path="/home/nginx/logs/nginx.pid" #nginx的pid [ -d $logs_backup_path ]||mkdir -p $logs_backup_path rq=`date +%Y%m%d` #mv ${logs_path}${logs_access}.log ${logs_backup_path}/${logs_access}_${rq}.log mv ${logs_path}${logs_error}.log ${logs_backup_path}/${logs_error}_${rq}.log kill -USR1 $(cat /home/nginx/logs/nginx.pid)
定时任务(按天进行日志切割)
crontab -e #注意是 -e
59 23 * * * bash /home/nginx/logs/cut_ngnix_log.sh #每天23:59分开始执行;