【问题标题】:How to set limit for Nginx log files on Mac OS?如何在 Mac OS 上设置 Nginx 日志文件的限制?
【发布时间】:2022-02-20 10:51:07
【问题描述】:

Nginx 占用所有可用磁盘空间。如何在 Mac OS 上设置日志文件的限制?

【问题讨论】:

    标签: macos nginx


    【解决方案1】:

    轮换日志文件。在 OS X 上,newsyslog 是执行此操作的首选实用程序。在/etc/newsyslog.d/nginx.conf中设置这样的文件:

    # logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
    /var/log/nginx.log     deceze:wheel     644  2     1024 *     J
    

    阅读https://www.newsyslog.org/manual.html了解更多信息。

    【讨论】:

    • 感谢您的回答! :)
    • 不应该向 nginx 主进程发送SIGUSR1 信号吗?或者这可以跳过,因为日志文件没有被删除而是设置为空?
    • @Paolo 好点,我实际上不能肯定地回答这个问题。你可能应该。
    【解决方案2】:

    基于@deceze 的回答,这里是 Apple Apache 配置的改编版本,适用于 Homebrew 安装的nginx

    #logfilename                            [owner:group]  mode count  size   when  [flags]  [/pid_file]                       [sig_num]
    /opt/homebrew/var/log/nginx/access.log  _nginx:_nginx  644  10     20480  *     Z        /opt/homebrew/var/run/nginx.pid   30
    

    这是假设您以 user:group _nginx:_nginx 的身份运行。它将正确的SIGUSR1 信号(macOS 上为 30)发送到nginx。也改为使用gzip 而不是bzip2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-11
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      相关资源
      最近更新 更多