Nginx日志切割
#vim rizhi.sh
#该脚本为每日凌晨执行
#!/bin/bash
base_path='/data/nginx/nginx-server/logs'
log_path=$(date -d yesterday +"%Y%m")
evday=$(date -d yesterday +"%Y%m%d")
cache_filepath='/data/nginx/nginx-server/proxy_cache'
mkdir -p $base_path/$log_path/$evday
############xxx日志切割###############
#xxx.log
mv $base_path/xxx.log $base_path/$log_path/$evday/xxx$evday.log
touch $base_path/xxx.log
#可选删除反向代理缓存内容
#cd $cache_filepath
#rm -rf *
#优雅的让nginx重载生效
kill -USR1 `cat /data/nginx/nginx-server/logs/nginx.pid`
#方式2
nginx -s reload
#docker 方式
docker exec 5a044a743e49 nginx -s reload
#创建linux任务计划程序
0 1 * * * sh /data/nginx/rizhi.sh
评论区