1. Create log directory
Nginx's default log directory may have a smaller hard disk space, so create a log directory based on the disk's space condition
Example: Mkdir/backup/nginx_logs
2. Modify Nginx configuration file
Configure the Nginx log directory to point to the directory you just created
In the configuration file, write:
Write on the server or HTTP or location block according to the time situation, this example is written in the server block
Access_log/backup/nginx_logs/access.log combined;
The above combined is the default log format for Nginx, and if you do not write it, you need to redefine it.
In this case, the combined is written directly, and this format awstats also recognized.
3, the use of logrotate management
The logrotate system comes with automatic timing and starts at 4:02
The configuration file is as follows:
/backup/nginx_logs {
Daily
missingok
rotate 7
nocompress
prerotate
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update -config =yoursite.com
endscript
postrotate
if [-f/usr/local/nginx/logs/nginx.pid]; then
kill-usr1 ' cat/usr/local/nginx/logs/nginx.pid '
fi
endscript
Before each rotate, will call Awstats generate statistics, rotate will be sent to the Nginx after the log to write people a new blank log file
Logrotate will use the/etc/logrotate.conf configuration file and all the configuration files in/ETC/LOGROTATE.D, so no need to change the logrotate configuration, just go to/ETC/LOGROTATE.D to add the above configuration file
Write the configuration file must be careful, or debug is troublesome, such as you put the configuration file nocompress removed, thought will default to use the compress in/etc/logrotate.conf, actually not, if/etc/ Configuration file Error in LOGROTATE.D, Logrotate will not be replaced with/etc/logrotate.conf, and there is no error message in/var/log/messages and the system's outgoing mail, unless the configuration file has an obvious error, the/var /log/messages and the system's outgoing mail response.
Nginx Log Management configuration