Nginx日志配置推荐
Nginx 刘宇帅 6年前 阅读量: 2081
推荐日志配置
log_format main 'remote_addr=[$remote_addr] http_x_forward=[$http_x_forwarded_for] time=[$time_local] request=[$request] '
'status=[$status] byte=[$bytes_sent] elapsed=[$request_time] upstream_connect_time=[$upstream_connect_time] upstream_response_time=[$upstream_response_time] '
'refer=[$http_referer] body=[$request_body] ua=[$http_user_agent] cookie=[$http_cookie] gzip=[$gzip_ratio] '
'msec=[$msec] http_host=[$http_host] http_accept=[$http_accept|$http_accept_encoding|$http_accept_language] '
'sent_http_set_cookie=[$sent_http_set_cookie]';
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") { #日志拆分
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
set $minutes $5;
set $seconds $6;
}
access_log /yourLogPath/prefix-$year-$month-$day-access.log main;
与此配合的crontab删除日志,每30天删除30天以前的日志
* * */30 * * cd /yourLogFilePath && find ./prefix*.log -mtime +30 |xargs -i rm {}