#!/bin/bash
#Rotate the Nginx logs to prevent a single logfile from consuming too much disk space.
LOGS_PATH=/usr/local/nginx/logs
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
## 向 Nginx 主程序發送 USR1 信号。USR1 信号是重新打開日志檔案
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
vi /etc/crontab
* * * root /usr/local/nginx/logs/nginxLogRotate.sh