为了账号安全,请及时绑定邮箱和手机立即绑定

求指点,Nginx是自己不能做日志切割这件事吗?

求指点,Nginx是自己不能做日志切割这件事吗?

牛魔王的故事 2023-04-16 18:14:25
Nginx的log都是写在一个文件里的,我需要每天一个Nginx Log网上看到很多办法,都是写脚本,定式切割Log文件
查看完整描述

2 回答

?
富国沪深

TA贡献1790条经验 获得超9个赞

确认cron在运行

service crond status

修改配置文件

vi /etc/crontab

确认定时任务

vi /etc/cron.daily/logrotate

编写logrotate配置文件 vi /etc/logrotate.d/nginx

/var/log/nginx/*.log {        #指定转储周期为每天
        daily
        missingok        #指定日志文件删除之前转储的次数,0 指没有备份,5 指保留5 个备份
        rotate 5
        #compress
        #delaycompress
        #如果是空文件的话,不转储
        notifempty        #create 640 root adm
        sharedscripts
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

测试配置

/usr/sbin/logrotate -f /etc/logrotate.d/nginx


查看完整回答
反对 回复 2023-04-20
?
守着一只汪

TA贡献1872条经验 获得超3个赞

最简单的办法就是直接在配置文件中进行配置:

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {    set $year $1;    set $month $2;    set $day $3;
}
access_log  /home/wwwlogs/$year-$month-$day-bbs-access.log access;


查看完整回答
反对 回复 2023-04-20
  • 2 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信