首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >nginx日志旋转配置

nginx日志旋转配置
EN

Server Fault用户
提问于 2010-12-04 21:44:40
回答 2查看 11.5K关注 0票数 3

旋转nginx日志文件的最佳方法是什么?在我看来,我应该在/etc/logrotate.d/中创建一个文件"nginx“,并用下面的代码填充它,然后执行/etc/init.d/syslog重新启动。

这将是我的配置(我还没有测试它):

代码语言:javascript
运行
复制
 /usr/local/nginx/logs/*.log {
    #rotate the logfile(s) daily
    daily
    # adds extension like YYYYMMDD instead of simply adding a number
    dateext
    # If log file is missing, go on to next one without issuing an error msg
    missingok
    # Save logfiles for the last 49 days
    rotate 49
    # Old versions of log files are compressed with gzip
    compress
    # Postpone compression of the previous log file to the next rotation cycle
    delaycompress
    # Do not rotate the log if it is empty
    notifempty
    # create mode owner group
    create 644 nginx nginx
    #after logfile is rotated and nginx.pid exists, send the USR1 signal
    postrotate
       [ ! -f /usr/local/nginx/logs/nginx.pid ] || kill -USR1 `cat
       /usr/local/nginx/logs/nginx.pid`
    endscript
 }

我在/usr/local/nginx/ error.log /中同时拥有error.log和error.log文件,并且希望每天都轮流使用。有人能告诉我“约会”是否正确吗?我希望日志文件名类似于“access.log.log-2010-12-04”。还有一件事:我可以每天在特定的时间(例如晚上11点)旋转日志吗?如果是这样的话,是怎么做的?谢谢。

EN

回答 2

Server Fault用户

发布于 2014-04-17 10:45:38

您可以同时旋转所有vhost:

代码语言:javascript
运行
复制
/var/www/vhosts/*/logs/*.log { ... }
票数 1
EN

Server Fault用户

发布于 2010-12-04 22:22:21

dateext的值由dateformat指令提供,默认为%Y%m%d (年份、月和日)。您可以像%Y-%m-%d一样定制它。

如果您已经安装并工作了logrotate,很可能它每天都会作为cron作业运行,您只需找到它来更改时间(请记住,其他东西会影响anacron的使用,但每个系统都会有所不同)。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/209177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档