`

Nginx: host.access.log日志切割

阅读更多

随着几天下来nginx的host.access.log逐渐膨胀.

理想的做法就是根据每天进行区分日志文件,如host.access_20120815.log等, 日志保留最近10天的, 超过10天的日志文件则进行删除.

根据上需求进行nginx的日志切割.

1. 脚本nginxcutlogs.sh

[devwqs@rehserver bin]$ more nginxcutlogs.sh
#!/bin/bash

# 1. move host.access.log to host.access_20120821.log
logs_path="/home/devwqs/nginx/logs/"
mv ${logs_path}host.access.log ${logs_path}host.access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /home/devwqs/nginx/logs/nginx.pid`

# 2. delete all host.access_2012xxxx.log which overtime 10 days
find ${logs_path} -name 'host.*.log' -type f -mtime +10 -exec rm {} \;

  

2. 使用crontab进行把上述脚本发布到定时任务, 每天凌晨0.01分定时执行nginxcutlogs:

#1. 编辑devwqs的crontab定时任务
[devwqs@rehserver bin]$ crontab –e 
1 0 * * * sh /home/devwqs/bin/nginxcutlogs.sh

#2. 重新启动crontab
[devwqs@rehserver bin]$ cd /etc/init.d
[devwqs@rehserver init.d]$ sudo ./crond restart
Stopping crond: [  OK  ]
Starting crond: [  OK  ]

 

注意: 一定要把crontab重启:

sudo ./crond restart

ubuntu使用: service cron restart

crontab学习资料:

http://blog.csdn.net/sipsir/article/details/3973713

http://os.51cto.com/art/200512/13558.htm

3
6
分享到:
评论

相关推荐

    filebeat-6.6.1-linux-x86_64.tar.gz

    # 修改数据来源,配置为nginx的日志目录,包括access.log及error.log filebeat.inputs: - type:log enabled: true paths: - /var/log/nginx/*.log # kibana相关设置,配置为kibana服务器地址 setup.kibana: ...

    PHP 仿陌陌直播

    #access_log logs/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50...

    Nginx中部署Angular项目遇到的坑巨坑

    网上搜索Angular 项目编译后部署到 Nginx 中的方法,多数文章都介绍了需要在 Nginx 中的配置文件的 ... access_log /var/log/nginx/host.access.log main; location / { root /chanchaw/app/angular; index index

    反向代理Nginx

    #access_log logs/host.access.log main; root E:\yuehou\git\web-h5\dist; location / { try_files $uri $uri/ /index.html; } #error_page 404 /404.html; # redirect server error pages to the ...

    配置好的nginx,Windows版本,解压即用只需稍微修改下service即可。

    #access_log logs/host.access.log main; # 静态页面目录 root E:\workSpace\本地静态资源; # 默认首页 index index.html; location = / { index login.html index.html index.htm; } # 用户浏览器端的...

    权限问题导致Nginx 403 Forbidden错误的解决方法

    今天在一个新的环境上安装nginx,结果访问的都是403 通常显示403我立马都会想到路径配置不对,但我仔细看了一下,目录路径... #access_log logs/host.access.log main;    location / {  root /root/html;  in

    Nginx屏蔽F5心跳日志、指定IP访问日志

    代码如下: location / {  proxy_redirect off;  proxy_set_header Host $host;  proxy_set_header X-Real-IP $remote_addr;... access_log /var/log/nginx/nginx_access_abres.log;  } } 注:192.1

    NGINX-Cookbook:NGINX食谱,由Packt发行

    NGINX食谱 这是发布的的代码存储库。 它包含从头到尾完成本书所必需的所有支持项目文件。 关于这本书 本书还重点介绍了NGINX的关键功能,例如... access_log /var/log/nginx/log/host.access.log combined; locatio

    Nginx定义域名访问方式

    #access_log logs/host.access.log main; location / { root html-hehe; index index.html index.htm; } } 配置完之后 在sbin 目录下执行命令 ./nginx -s reload 重新加载配置文件 加载之后浏览器地

    tentarun:在多台服务器上运行并获取输出

    tentarun -u username -p password -h host1,host2,host3 "tail /var/log/nginx/access.log" tentarun -p password -h host1,host2,host3 "tail /var/log/nginx/access.log" 使用用户名和密钥文件 tentarun -u ...

    nginx 多站点配置方法集合

    那么我们开始吧: 1、为我们的站点创建配置文件 我是这么做的,在nginx的配置文件conf目录下创建一个专门存放VirtualHost的目录,命名为vhosts_conf,... #域名 #access_log logs/host.access.log main; location /

    Nginx配置文件(nginx.conf)配置详解(总结)

    现在经常碰到有新用户问一些很基本的问题,最近整理了一下,Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组。window下不指定 worker_processes 8; 工作进程:数目。根据...

    Nginx下支持Thinkphp URL Rewrite的配置示例

    概述 Nginx服务器现在已经成为相当流行的开源Web服务器,很多生产环境也都在使用Nginx服务器。现在做项目大多数时候都是在使用ThinkPHP,但是Nginx默认不支持... #access_log logs/host.access.log main; # Load confi

    Nginx+Tomcat负载均衡

    access_log logs/access.log; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; client_header_buffer_size 1k; large_client_header_buffers 4 4k; sendfile on; tcp_nopush on; ...

    nginx 配置模板

    access_log logs/access.log; root "E:/front"; proxy_set_header Host $host; set $uid "-"; # 存在值则赋值 if ( $http_cookie ~* "at_uvid=(\S+)(;.*|$)"){ set $uid $1; } location ^~/test-...

    Nginx访问日志及错误日志参数说明

    说明: nginx日志主要有两种:访问日志、错误日志。...访问日志[Access.log] log_format main ‘$remote_addr $remote_user [$time_local] “$request” $http_host ‘ ‘$status $upstream_status

    tomcat8 + nginx + memcached + cas 实现负载均衡的配置包

    access_log logs/host.access.log main; #对 "/" 所有应用启用负载均衡 location / { proxy_pass http://127.0.0.1; #保留用户真实信息 proxy_set_header X-Real-IP $remote_addr; proxy_set_header ...

    zabbix监控Nginx/Tomcat/MySQL的详细教程

    zabbix监控Nginx A机器:zabbix服务端(192.168.234.128) B机器:zabbix客户端(192.168.234.125) 在B机器(zabbix客户端)操作: ... access_log off; allow 127.0.0.1; deny all; } 重载nginx配置: [root@c

    详解nginx 配置多个tomcat共用80端口

    场景:项目1放在tomcat1中,项目2放在tomcat2中,两个tomcat放在同一台服务器上,需要共享80端口访问 注意:这里和集群部署是不同的,集群部署是一个项目放在多个tomcat中。... #access_log logs/host.acces

    vue.js使用代理和使用Nginx来解决跨域的问题

    使用Nginx 反向代理解决跨域问题(vue.js使用代理去掉vue.js因为跨域而触发的options请求) 我们的项目还是需要node.js作为容器的 一、Windows 下安装Nginx (官网下载稳定版...#access_log logs/host.ac

Global site tag (gtag.js) - Google Analytics