Author: zhanhailiang date: by default, nginx will generate only one accesslog and one errorlog, and the log file will become very large as it accumulates every day. if you need to analyze the log, whether using script analysis or downloading logs for local analysis,
Author: zhanhailiang date:
By default, nginx generates only one access. log and an error. logs are accumulated every day, and the log files become very large. if you need to analyze the logs, whether using script analysis or downloading the logs for local analysis, it is not convenient. This is also required for php logs.
Therefore, splitting access logs and error logs every day is conducive to log analysis.
#! /Bin/sh # for daily scheduled splitting, you can select the corresponding version for low-end users to run ngPid = '/usr/local/nginx/logs/nginx. pid 'phpfpmpid = '/usr/local/php/var/run/php-fpm.pid' ngLogs = '/usr/local/nginx/logs' # access. log error. logphpLogs = '/usr/local/php/log' # errors. log slow. logsaveLog = '/home/service/logs' top = $ saveLog/$ (date + % Y)/$ (date + % m) mkdir-p $ top/nginxif [-f $ ngLogs/access. log]; then mv $ ngLogs/access. log $ top/nginx/access. $ (date + % Y % m % d ). logfi if [-f $ ngLogs/error. log]; then mv $ ngLogs/error. log $ top/nginx/error. $ (date + % Y % m % d ). logfi echo 'cat $ ngPid 'kill-USR1 'cat $ ngPid' # repeat the log file Reopen the log files mkdir-p $ top/phpif [-f $ phpLogs/errors. log]; then mv $ phpLogs/errors. log $ top/php/errors. $ (date + % Y % m % d ). logfi if [-f $ phpLogs/php-fpm.log]; then mv $ phpLogs/php-fpm.log $ top/php-fpm. $ (date + % Y % m % d ). logfi echo 'cat $ phpfpmpid' kill-USR1 'cat $ phpfpmpid' # Restart the php log Reopen the log files chmod-R 777 $ top