Nginx does not support using cronolog to rotate logs like Apache, but you can use the following methods to cut log files:
Mv/data1/logs/access. log/data1/logs/20111030.log
Kill-USR1 Nginx master process number
Use the mv command to rename the log file to/data1/logs/20111030.log, and then send the kill-USR1 signal to the main process ID of Nginx to enable Nginx
Generate a new log file/data1/logs/access. log.
To regularly cut logs every day, you also need to use crontab. We can write a daily cut log by year or month.
Shell script for storing logs in directories:
The code is as follows: |
Copy code |
#! /Bin/bash # This script run # The Nginx logs path Logs_path = "/home/www/data/logs /" Mkdir-p $ {logs_path} $ (date-d "yesterday" + "% Y")/$ (date-d "yesterday" + "% m ")/ Mv $ {logs_path} access. log $ {logs_path} $ (date-d "yesterday" + "% Y")/$ (date-d "yesterday" + "% M ")/access _ $ (date-d" yesterday "+" % Y % m % d "). log Kill-USR1 'cat/usr/local/servers/nginx. Pid' |
Grant executable permissions:
Run crontab-e to enter the editing status.
The code is as follows: |
Copy code |
00 04 ***/root/cut_logs.sh |
In this way, your system will automatically cut nginx logs at every morning.
If you want to change the other time, you can modify 00 04 ***/root/cut_logs.sh, for example, to cut nginx access at every day.
Question Log
Crontab-e
Enter the following content:
The code is as follows: |
Copy code |
00 00 ***/bin/bash/usr/local/nginx/sbin/cut_nginx_log.sh |
You only need to modify the preceding number.