Nginx日志按日期存放
Nginx日志如果放在一个文件里,可能文件会变得很大,可以通过按日期存放,避免单文件过大。
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
map $time_iso8601 $logdate {
'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
}
access_log off;
server {
listen 80;
server_name localhost;
root C:/dev/nginx/html;
index index.html;
charset utf-8;
access_log logs/access-$logdate.log main;
}
}