nginx日志切割
- 备份日志文件 mv access.log bak.log
- 打开新的日志文件 ../sbin/nginx -s reopen
- 一般会使用脚本来执行日志切割的操作 vim rotate.sh
#!/bin/bash
# 备份日志存放路径
LOGS_PATH=/usr/local/nginx/logs/history
# 当前日志存放路径
CUR_LOGS_PATH=/usr/local/nginx/logs
# 获取系统时间
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
# 移动日志文件
mv ${CUR_LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${CUR_LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
# 执行nginx日志切割
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
Comments NOTHING