1. edit the shell program for log cutting. set the directory to [plain] viewplaincopy # vi/data/nginx/cut_nginx_log.sh and enter the code: [python] viewplaincopy #! /Bin/bash # Thisscriptrunat00: 00 functioncutAccess () {di
1. edit the shell program for log cutting and customize the Directory
[Plain]View plaincopy
# Vi/data/nginx/cut_nginx_log.sh
Enter the code:
[Python]View plaincopy
#! /Bin/bash
# This script run at 00:00
Function cutAccess ()
{
Dir = $1
Newdir = "$ {dir}/$ (date-d" yesterday "+" % Y ")/$ (date-d" yesterday "+" % m ")"
Suffix = $ (date-d "yesterday" + "% Y % m % d ")
Mkdir-p $ newdir
Mv $ {dir}/access. log $ {newdir}/access. $ suffix. log
}
CutAccess "/home/wwwlogs/www.yourdomain.com /"
CutAccess "/home/wwwlogs/www.yourdomain-1.com /"
CutAccess "/home/wwwlogs/www.yourdomain-2.com /"
# Restart nginx
Kill-HUP 'cat/usr/local/nginx/logs/nginx. pid'
2. add a scheduled task to automatically cut at every day
[Plain]View plaincopy
# Crontab-e
0 0 ***/bin/bash/data/nginx/cut_nginx_log.sh
3. nginx log format
[Plain]View plaincopy
Log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
Access_log/home/wwwlogs/www.yourdomain.com/access.log access;