发布时间: 2024-2-28 文章作者: myluzh 分类名称: Nginx 朗读文章
root@iZbp12bkuvg20e1j3y9gtvZ:/etc/logrotate.d# cat /etc/nginx/nginx.conf http { # ... log_format main escape=none '$remote_addr - $remote_user [$time_iso8601] "$request_method $scheme://$host$request_uri" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" time=$request_time upstream_addr=$upstream_addr' '\n $request_body'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; # ...当你定义Nginx日志格式时,你可以指定使用哪些变量来记录不同的信息。在你提供的日志格式中,每个变量都代表着不同的信息
root@iZbp12bkuvg20e1j3y9gtvZ:/etc/logrotate.d# cat /etc/logrotate.d/nginx /var/log/nginx/*.log { daily missingok rotate 14 compress delaycompress notifempty create 0640 www-data adm sharedscripts prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi \ endscript postrotate invoke-rc.d nginx rotate >/dev/null 2>&1 endscript }2、按照日期保存,最多14天
root@iZbp12bkuvg20e1j3y9gtvZ:/etc/logrotate.d# cat /etc/logrotate.d/nginx /var/log/nginx/*.log { daily missingok rotate 14 compress dateext # 可选:设置日期格式,这里使用默认的'%Y%m%d',即年月日格式 #dateformat -%Y%m%d delaycompress notifempty create 0640 www-data adm sharedscripts prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi \ endscript postrotate invoke-rc.d nginx rotate >/dev/null 2>&1 endscript }
标签: nginx logging logrotate log_format access_log error_log
发表评论