vim /usr/local/nginx/logs/nginx_log.sh

#! /bin/bash

logs_path="/usr/local/nginx/logs/"

log_name="access.log"

pid_path="/usr/local/nginx/logs/nginx.pid"


[ -d /usr/local/nginx/logs/access_log ] || mkdir /usr/local/nginx/logs/access_log

access_logs_path="/usr/local/nginx/logs/access_log/"

mv ${logs_path}${log_name} ${access_logs_path}$(date --date="yesterday"+"%Y-%m-%d")_${log_name}\

kill -USR1 `cat ${pid_path}`


cd ${access_logs_path}

find . -ctime +30 -name "*access.log" |xargs rm -f

exit 0 


crontab -e

00 00 * * * /usr/local/nginx/logs/nginx_log.sh

service crond restart