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,反向代理及日志管理,请注意只适用于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 ...
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 #...
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....
Discover possible interactions between Nginx and Apache to get the best of both worlds Learn to exploit the features offered by NGinx for your web applications Get the newest techniques available, ...
ffmpeg是一个视频转码插件,比如rtsp转rtmp rtsp转hls等等,Nginx插件是一个搭建服务的插件
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 1.22.0 Linux 版本,解压安装。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理...能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。
nginx 离线安装包nginx 离线安装包
nginx镜像资源nginx镜像资源nginx镜像资源nginx镜像资源nginx镜像资源nginx镜像资源
Nginx安装包Nginx安装包
Nginx 1.8.0 安装简述 Nginx 是一种流行的开源 Web 服务器软件,广泛应用于生产环境中。为了帮助读者快速掌握 Nginx 的安装过程,本文将详细介绍 Nginx 1.8.0 的安装步骤。 一、下载依赖项 在安装 Nginx 之前,...
亲测好用.nginx-1.13.3,nginx1.13.3不存在信息泄漏漏洞安全稳定nginx版本,不存在漏洞 nginx-1.13.3 nginx1.13.3 安全稳定 nginx版本
nginx替代apache,nginx替代方案,nginx代替apache与jbos,nginx+jboss结合
3.找到D:\nginx\conf下nginx.conf文件用记事本打开 在文段末尾大括号前加上 include proxy.conf;(就是加载刚刚新建的那个文件(注意路径)) 4.进入cmd 进入D盘: d: 进到nginx文件夹下:cd nginx 启动nginx.exe:...
nginx.conf nginx-1.20.1.tar.gz 这是关于centos8的nginx 和nginx 的配置https文件
也可以通过查看Nginx日志文件定位到Nginx重启失败的原因,Nginx日志文件的路径一般在:/var/log/nginx目录下 总结 文章没什么技术含量,每天都攒一点基础知识 您可能感兴趣的文章:nginx centos 服务开机启动设置...
nginx安装环境及nginx_1.18.0安装包,gcc、g++、pcre、zlib、nginx包
Nginx全能指南是一本介绍Nginx服务器的书,首先,简要介绍Nginx的基本概念和作用,如反向代理、负载均衡等。然后,列举Nginx的优点,如高性能、可扩展性、稳定性等。接着,介绍如何安装和配置Nginx,并提供一些实用...