Nginx and Cronolog
I recently setup Nginx for one of our webservers and needed to hook cronolog up to it for all the normal reasons you want cronolog.
But Nginx doesn't support piped logging yet :( But we can use fifo's though to accomplish the same thing :)
- Configure nginx.conf to log to logs/access.log and logs/error.log like normal.
- Remove those files from the logs directory.
- Recreate them as fifo's using "mkfifo access.log" and "mkfifo error.log".
- Tweak the nginx startup script to start cronolog just before nginx.
Something like this:
(cat /usr/local/nginx/logs/access.log |\
/usr/local/sbin/cronolog -l /var/log/nginx/access.log \
/var/log/nginx/%Y/%m/%d/%H/access.log) &
(cat /usr/local/nginx/logs/error.log |\
/usr/local/sbin/cronolog -l /var/log/nginx/error.log \
/var/log/nginx/%Y/%m/%d/%H/error.log) &
That's it. It seems that you'd need to stop cronolog when shutting down nginx, but at least on CentOS this isn't required. I suspect that when the fifo is closed for writing it gets closed for reading and cat exists which exits cronolog as well. Would love it it someone could confirm that though.
UPDATE
Igor Sysoev made the comment that the above might hinder nginx's performance because of context switching and the blocking between the worker processes. So instead of the above you can simulate it with the following as an hourly cron task:
log_dir="/var/log/nginx"
date_dir=`date +%Y/%m/%d/%H`
/bin/mkdir -p ${log_dir}/${date_dir} > /dev/null 2>&1
/bin/mv ${log_dir}/access.log ${log_dir}/${date_dir}/access.log
/bin/mv ${log_dir}/error.log ${log_dir}/${date_dir}/error.log
kill -USR1 `cat /var/run/nginx.pid`
/bin/gzip ${log_dir}/${date_dir}/access.log &
/bin/gzip ${log_dir}/${date_dir}/error.log &
我还是很喜欢nginx作者(Igor Sysoev )的方案!
分享到:
相关推荐
**Nginx 1.7.2 和 Cronolog 1.6.2:构建高效反向代理与日志管理系统** Nginx 和 Cronolog 是在 Linux 系统中广泛使用的两个工具,它们分别用于网络服务器的反向代理服务和日志管理。在本文中,我们将深入探讨这两个...
NGINX caching and cache clustering are powerful tools that can exponentially improve the performance of your website while also reducing hardware requirements, complexity, and cost. This ebook is a ...
标题 "NGINX and FFMPEG.rar" 提到的两个核心工具是Nginx和FFmpeg,它们在IT领域,特别是视频流媒体服务中扮演着重要角色。FFMPEG是一款强大的开源命令行工具,用于处理音频和视频文件,包括转换、编码、解码、分割...
3. 集成:在Apache或Nginx等Web服务器中,通过修改配置文件(如`httpd.conf`或`nginx.conf`),将日志输出指向cronolog进程,以便让cronolog处理日志。 4. 管理:一旦启用cronolog,用户需要定期检查日志目录,确保...
1、下载(最新版本) # wget http://cronolog.org/download/cronolog-1.6.2.tar.gz 2、解压缩 # tar zxvf cronolog-1.6.2.tar.gz 3、进入cronolog安装文件所在目录 # cd cronolog-1.6.2 4、运行安装 # ./configure #...
- **Nginx and Cronolog**:Cronolog是一个日志轮换脚本,可以按时间戳切割日志文件,便于后续的日志分析。 - **Nginx如何不记录部分日志**:通过配置可以排除某些请求的日志记录,以减少日志文件的大小和处理开销...
Teaches you to start up Nginx and quickly take your expertise to a level where you can comfortably work with various aspects of the web server and make informed design decisions for your web farm....
arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构...
explore advanced features of both NGINX and NGINX Plus, the free and licensed versions of this server. You’ll find recipes for: - High-performance load balancing with HTTP, TCP, and UDP - Traffic ...
现在,我们可以下载Nginx的源代码包`nginx-1.20.1.tar.gz`。你可以通过wget或者浏览器将文件下载到本地,然后解压: ```bash wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -zxvf nginx-1.20.1.tar.gz cd...
cronolog的配置文件通常设置在HTTP服务器的配置中,例如Apache或Nginx的配置文件,通过将日志输出重定向到cronolog来实现日志分割。 安装cronolog的步骤简单明了,正如描述中提到的,解压文件后,执行以下命令: 1...
**Nginx版本升级步骤详解** 在Web服务器领域,Nginx以其高性能、低内存消耗以及高并发处理能力而备受青睐。随着新版本的发布,可能会包含性能优化、安全修复和新特性,因此定期更新Nginx版本是必要的。本文将详细...
Nginx 1.22.0 Linux 版本,解压安装。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理...能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。
这个名为"nginx-linux-arm64.zip"的压缩包提供的是专为ARM64架构(也称为AArch64)编译的Nginx版本,适用于基于Linux操作系统的64位ARM处理器设备,如树莓派、某些云服务器或嵌入式系统。无需繁琐的编译过程,只需...
Nginx 1.24.0 是 Nginx 开源项目发布的一个重要更新版本,该版本在性能优化、功能增强以及安全性提升方面带来了诸多改进。当您下载 Nginx 1.24.0 的压缩包时,您将获得一个包含 Nginx 源代码的压缩文件,通常命名为 ...
**Nginx 1.13.3 版本详解** Nginx 是一款高性能的 HTTP 和反向代理服务器,广泛应用于网站托管、负载均衡以及应用程序交付等领域。它以其高效、稳定和轻量级的特性著称,尤其在处理静态内容和高并发请求时表现优秀...
nginx1.16镜像包 使用docker load -i xx.tar 拉取镜像 使用docker images 查看是否成功。 运行容器 docker run --name nginx-test -p 8080:80 -d nginx 参数说明: --name nginx-test:容器名称。 -p 8080:80: ...
Nginx 1.22.0 Windows版本,解压安装。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)...能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。