Nginx 访问日志轮询切割脚本

 #!/bin/sh
Dateformat=`date +%Y%m%d`
Basedir="/application/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir||exit 1
[ -f ${Logname}.log ]||exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
/bin/mv access_bbs.log ${Dateformat}_access_bbs.log
/bin/mv access_blog.log ${Dateformat}_access_blog.log
$Basedir/sbin/nginx -s reload

配置www.conf

 [root@lnmp02 scripts]# vim /application/nginx/conf/extra/www.conf
server {
listen 80;
server_name www.judong.org judong.org;
location / {
root html/www;
index index.html index.htm;
}
access_log logs/access_www.log main;
}

配置bbs.conf

 [root@lnmp02 scripts]# vim /application/nginx/conf/extra/bbs.conf
server {
listen 80;
server_name bbs.judong.org;
location / {
root html/bbs;
index index.html index.htm;
}
access_log logs/access_bbs.log main; ##添加访问日志
}
~

配置blog.conf

 [root@lnmp02 scripts]# vim /application/nginx/conf/extra/blog.conf
server {
listen 80;
server_name blog.judong.org;
location / {
root html/blog;
index index.html index.htm;
}
access_log logs/access_blog.log main;
}

测试

 [root@lnmp02 scripts]# ll /application/nginx/logs/
total 40
-rw-r--r--. 1 root root 756 Mar 3 22:07 20160315_access_www.log
-rw-r--r--. 1 root root 0 Mar 15 09:27 20160316_access_www.log
-rw-r--r--. 1 root root 0 Mar 17 2016 20160317_access_bbs.log
-rw-r--r--. 1 root root 0 Mar 17 2016 20160317_access_blog.log
-rw-r--r--. 1 root root 0 Mar 17 2016 20160317_access_www.log
-rw-r--r--. 1 root root 0 Mar 17 2016 access_bbs.log
-rw-r--r--. 1 root root 0 Mar 17 2016 access_blog.log
-rw-r--r--. 1 root root 22177 Mar 3 22:06 access.log
-rw-r--r--. 1 root root 0 Mar 17 2016 access_www.log
-rw-r--r--. 1 root root 2088 Mar 17 2016 error.log
-rw-r--r--. 1 root root 5 Mar 3 19:31 nginx.pid

配置定时任务使得每天0点整执行脚本

 [root@lnmp02 scripts]# crontab -l
######cut nginx access_www.log########
00 00 * * * /bin/sh /server/scripts/cut_nginx_log.sh >/dev/null 2>&1

Nginx 访问日志轮询切割的更多相关文章

  1. Nginx的继续深入(日志轮询切割,重写,负载均衡等)

    Nginx的访问日志轮询切割 通常什么情况Nginx会把所有的访问日志生成到一个制定的访问日志文件access.log里面,但时间一长,日志个头很大不利于日志的分析和处理. 有必要对Nginx日志进行 ...

  2. nginx日志配置,以及日志轮询

    一.为nginx配置错误日志 Nginx错误日志是调试nginx的重要手段,属于核心功能模块的参数(ngx_core_module)该参数名字为err_log,是放在Main区块中全局配置 err_l ...

  3. 按日期切割nginx访问日志--及性能优化

    先谈下我们需求,一个比较大的nginx访问日志,根据访问日期切割日志,保存在/tmp目录下. 测试机器为腾讯云机子,单核1G内存.测试日志大小80M. 不使用多线程版: #!/usr/bin/env ...

  4. Nginx访问日志、 Nginx日志切割、静态文件不记录日志和过期时间

    1.Nginx访问日志 配制访问日志:默认定义格式: log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_loc ...

  5. Nginx访问日志、日志切割、静态文件不记录日志和过期时间

    6月8日任务 12.10 Nginx访问日志12.11 Nginx日志切割12.12 静态文件不记录日志和过期时间 12.10 Nginx访问日志 除了在主配置文件nginx.conf里定义日志格式外 ...

  6. Linux centosVMware Nginx访问日志、Nginx日志切割、静态文件不记录日志和过期时间

    一.Nginx访问日志 vim /usr/local/nginx/conf/nginx.conf //搜索log_format  日至格式 改为davery格式 $remote_addr  客户端IP ...

  7. Nginx访问日志.Nginx日志切割

    11月27日任务 12.10 Nginx访问日志12.11 Nginx日志切割12.12 静态文件不记录日志和过期时间 1.Nginx访问日志 示例一: 日志格式 vim /usr/local/ngi ...

  8. nginx访问日志(access_log)

    一.nginx访问日志介绍 nginx软件会把每个用户访问网站的日志信息记录到指定的日志文件里,供网站提供者分析用户的浏览行为等,此功能由ngx_http_log_module模块负责,对应的官方地址 ...

  9. Apache日志轮询Cronolog安装及简单用法

    安装日志轮询工具cronolog: [root@bqh- tools]# tar xf cronolog-.tar.gz [root@bqh- tools]# cd cronolog- [root@b ...

随机推荐

  1. redis成长之路——(六)

    redis配置 为了码农在代码上只关心业务以及代码上的统一性,wenli.drive.redis内部使用配置来完成那些不同的场景,也就是说随便填填配置就能适应不同的场景! 当然配置多了码农也会受不了, ...

  2. C#异常处理经验(原则与方法)

         本文是异常处理经验性的文章,其实跟C#关系也不大.比较适合刚刚熟悉异常语法,而缺乏实战的读者.当然,经验老练的读者也可指出不足.给予意见.补充说明,一起完善文章,分享更多知识与经验.   1 ...

  3. 3.Kali 1.0 / 2.0 安装中文输入法(谷歌pinyin + 其他)

    1.kali默认是没有中午输入法的,需要自己安装一下 2.首先我们先获取root权限 dnt@HackerKali:~$ su密码: 3.安装中文输入法(apt-get 指令不会的同学可以学习一下基础 ...

  4. 在Windows Server 2012中如何快速开关桌面上经典的“计算机、我的文档”等通用图标

    我们都知道,在Windows Server 2012系列的服务器版本中都已经引入了Modern的现代界面作为默认的用户交互界面,同时满足视觉一致化,新版的服务器管理程序也做成了扁平化.因此传统的计算机 ...

  5. 多项目并行开发如何做到快速切换——sublime Text3

    sublime text有一个很人性化的功能,就是打开窗口的时候,它会把上一次关闭时的编辑器工作区状态完全复原(不论文件是否已经保存). 只有一个项目的时候,这个功能非常方便,可以保证重启电脑后cod ...

  6. mac linux rename命令行批量修改文件名

    我的mac使用命令行批量修改名字时发现居然没有rename的指令: zsh: command not found: rename 所以使用HomeBrew先安装一下: ➜ ~ brew install ...

  7. 没有神话,聊聊decimal的“障眼法”

    0x00 前言 在上一篇文章<妥协与取舍,解构C#中的小数运算>的留言区域有很多朋友都不约而同的说道了C#中的decimal类型.事实上之前的那篇文章的立意主要在于聊聊使用二进制的计算机是 ...

  8. iOS: 在UIViewController 中添加Static UITableView

    如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...

  9. C#基础知识七之const和readonly关键字

    前言 不知道大家对const和readonly关键字两者的区别了解多少,如果你也不是很清楚的话,那就一起来探讨吧!探讨之前我们先来了解静态常量和动态常量. 静态常量 所谓静态常量就是在编译期间会对变量 ...

  10. C#写文本日志帮助类(支持多线程)改进版(不适用于ASP.NET程序)

    由于iis的自动回收机制,不适用于ASP.NET程序 代码: using System; using System.Collections.Concurrent; using System.Confi ...