To write a script :
vim/usr/local/sbin/logrotate.sh//Join
#!/bin/bash
D= ' date-d '-1 day "+%f"
[-d/tmp/nginx_log] | | Mkdir/tmp/nginx_log
mv/tmp/access.log/tmp/nginx_log/$d. Log
/etc/init.d/nginx Reload 2>/dev/null
cd/tmp/nginx_log/
Gzip-f $d. Log
#! /bin/bash
Datedir= ' Date +%y%m%d '
/bin/mkdir/home/logs/$datedir >/dev/null 2>&1
/bin/mv/home/logs/*.log/home/logs/$datedir
/bin/kill-hup ' Cat/var/run/nginx.pid '
Log Format
Log_format main ' $remote _addr-$remote _user [$time _local] $request '
" $status" $body _bytes_sent "$http _referer"
' "$http _user_agent" "$http _x_forwarded_for";
log_format main1 ' $proxy _add_x_forwarded_for-$remote _user [$time _local] '
" $request" $status $body _bytes_sent '
' "$http _referer" "$http _user_agent"; This log format is that IP not only records the proxy IP but also records the remote client real IP.
error Log error_log log level
The error_log level is divided into debug, info, notice, warn, error, crit default to Crit, which defines the format behind the log name as follows:
Error_log/your/path/error.log Crit;
Crit logs are minimal, and debug logs are logged the most. If your nginx encounters some problems, such as 502 more frequent, but see the default error_log does not see meaningful information, then you can adjust the level of the error log, when you tune to the error level, the content of errors logging will be richer.
Nginx Log Cutting