首页 > 代码库 > Nginx 访问日志轮询切割
Nginx 访问日志轮询切割
默认情况下 Nginx 会把所有的访问日志生成到一个指定的访问日志文件 access.log 里,但这样一来,时间长了就会导致日志个头很大,不利于日志的分析和处理,因此,有必要对 Nginx 日志,按天或按小时进行切割,使其分成不同的文件保存。
[root@localhost conf]# cat cut_nginx_log.sh #!/bin/bashDateformat=`date +%Y%m%d`Basedir="/usr/local/nginx"Nginxlogdir="$Basedir/logs"Logname="access"[ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1[ -f ${Logname}.log ] || exit 1/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log$Basedir/sbin/nginx -s reload
[root@localhost nginx]# crontab -l0 0 * * * /bin/bash /usr/local/nginx/conf/cut_nginx_log.sh > /dev/null 2>&1
效果:
[root@localhost logs]# ll-rw-r--r--. 1 root root 0 May 25 18:57 20170521_access.log-rw-r--r--. 1 root root 0 May 25 18:57 20170522_access.log-rw-r--r--. 1 root root 0 May 25 18:57 20170523_access.log-rw-r--r--. 1 root root 0 May 25 18:57 20170524_access.log-rw-r--r--. 1 root root 0 May 25 18:57 20170525_access.log-rw-r--r--. 1 root root 0 May 25 18:57 access.log-rw-r--r--. 1 root root 6083 May 25 18:57 error.log-rw-r--r--. 1 root root 5 May 25 13:12 nginx.pid
Nginx 访问日志轮询切割
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。